Skip to content

Commit

Permalink
reexports
Browse files Browse the repository at this point in the history
  • Loading branch information
catalamarti committed Aug 4, 2024
1 parent 91436e4 commit 370816f
Show file tree
Hide file tree
Showing 9 changed files with 123 additions and 10 deletions.
3 changes: 3 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,10 @@ export(filterSettingInitServer)
export(filterSettingUi)
export(genericServer)
export(genericUI)
export(importSummarisedResult)
export(launchDynamicApp)
export(serverDynamic)
export(serverStatic)
export(splitBySettings)
export(studySelectInitServer)
export(studySelectServer)
Expand All @@ -19,4 +21,5 @@ export(uiDynamic)
export(uiStatic)
export(uploadDataInitServer)
export(uploadDataUi)
importFrom(omopgenerics,importSummarisedResult)
importFrom(rlang,.data)
4 changes: 4 additions & 0 deletions R/reexports.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@

#' @importFrom omopgenerics importSummarisedResult
#' @export
omopgenerics::importSummarisedResult
28 changes: 28 additions & 0 deletions R/server.R
Original file line number Diff line number Diff line change
Expand Up @@ -228,3 +228,31 @@ serverDynamic <- function(input, output, session) {

})
}

#' Provides the static server of the shiny app for a given set of resultType(s).
#'
#' @param resultType Character vector indicating the result_type of interest.
#' @param asText Whether to output a text object or to eval it.
#'
#' @return The server of interest.
#' @export
#'
serverStatic <- function(resultType = character(),
asText = FALSE) {
# initial checks
omopgenerics::assertCharacter(resultType, unique = TRUE)
omopgenerics::assertLogical(asText, length = 1)

# create server
x <- 'function(input, output, session) {}'

if (asText) {
x <- paste0("server <- ", x) |>
styler::style_text()
} else {
x <- x |>
rlang::parse_expr() |>
rlang::eval_tidy()
}
return(x)
}
29 changes: 27 additions & 2 deletions R/shinyApp.R
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ exportStaticApp <- function(data = list(),
resType <- omopgenerics::settings(data)[["result_type"]] |> unique()
mes <- "Data processed: {length(resType)} result type{?s} idenfied"
if (length(resType) == 0) {
resType <- character()
mes <- c("!" = paste0(mes, "."))
} else {
mes <- c("v" = paste0(mes, ": {.var {resType}}."))
Expand All @@ -47,14 +48,38 @@ exportStaticApp <- function(data = list(),

# create shiny
cli::cli_inform(c("i" = "Creating shiny from provided data"))

ui <- c(messageShiny(), uiStatic(resultType = resType, asText = TRUE))
server <- c(messageShiny(), serverStatic(resultType = resType, asText = TRUE))
global <- c(messageShiny(), global)
directory <- paste0(directory, "/shiny")
dir.create(paste0(directory, "/data"), recursive = TRUE)
writeLines(ui, con = paste0(directory, "/ui.R"))
writeLines(server, con = paste0(directory, "/server.R"))
writeLines(global, con = paste0(directory, "/global.R"))
writeLines(proj, con = paste0(directory, "/shiny.Rproj"))
omopgenerics::exportSummarisedResult(
data,
minCellCount = 0,
fileName = "results.csv",
path = paste0(directory, "/data"))
cli::cli_inform(c("v" = "Shiny created in: {.pkg {directory}}"))

# launch shiny
if (launch) {
cli::cli_inform(c("i" = "Launching shiny"))
#shiny::shinyAppDir(here::here(directory, "shiny"))
# still does not work
shiny::shinyAppDir(directory)
}

return(invisible())
}

messageShiny <- function() {
c(
paste0(
"# Generated by omopViewer ",
as.character(utils::packageVersion("omopViewer"))
),
"# Be careful editing this file", ""
)
}
Binary file modified R/sysdata.rda
Binary file not shown.
20 changes: 13 additions & 7 deletions R/ui.R
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ uiDynamic <- function() {
)
}


#' Provides the static UI of the shiny app for a given set of resultType(s).
#'
#' @param resultType Character vector indicating the result_type of interest.
Expand All @@ -64,10 +63,12 @@ uiStatic <- function(resultType = character(),
# create ui
x <- paste0(
'shinydashboard::dashboardPage(
shinydashboard::dashboardHeader(title = "omopViewer"),
shinydashboard::dashboardHeader(title = "My study"),
shinydashboard::dashboardSidebar(
shinydashboard::menuItem(
text = "About", tabName = "about", icon = shiny::icon("circle-info"))',
text = "About", tabName = "about", icon = shiny::icon("circle-info")),
shinydashboard::menuItem(
text = "Background", tabName = "background", icon = shiny::icon("magnifying-glass"))',
sidebar,
'),
shinydashboard::dashboardBody(
Expand All @@ -81,15 +82,20 @@ uiStatic <- function(resultType = character(),
href = system.file("www/css/sass.min.css", package = "omopViewer"))
),
shinydashboard::tabItems(
shinydashboard::tabItem(tabName = "about", omopViewer::aboutTab())',
body,
')
shinydashboard::tabItem(tabName = "about", omopViewer::aboutTab()),
shinydashboard::tabItem(
tabName = "background",
shiny::h4("Study background"),
shiny::p("You can use this section to add some background of your study")
)',
body,
')
)
)'
)

if (asText) {
x <- x |>
x <- paste0("ui <- ", x) |>
styler::style_text()
} else {
x <- x |>
Expand Down
14 changes: 13 additions & 1 deletion data-raw/internalData.R
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,16 @@ resultTypeTabs <- dplyr::tribble(
"summarise_cohort_characteristics", "Cohort characteristics", "people-group"
)

usethis::use_data(resultTypeTabs, overwrite = TRUE, internal = TRUE)
proj <- c(
"Version: 1.0", "", "RestoreWorkspace: Default", "SaveWorkspace: Default",
"AlwaysSaveHistory: Default", "", "EnableCodeIndexing: Yes",
"UseSpacesForTab: Yes", "NumSpacesForTab: 2", "Encoding: UTF-8", "",
"RnwWeave: Sweave", "LaTeX: pdfLaTeX"
)

global <- c(
"library(shiny)", "library(omopViewer)", "",
"data <- importSummarisedResult(here::here(\"data\"))"
)

usethis::use_data(resultTypeTabs, proj, global, overwrite = TRUE, internal = TRUE)
16 changes: 16 additions & 0 deletions man/reexports.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

19 changes: 19 additions & 0 deletions man/serverStatic.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 370816f

Please sign in to comment.