vignettes/shinyAppModules.Rmd
shinyAppModules.Rmd
The shiny app builder provides a way to combine different shiny
modules into a single app. For example, if you have a characterization
study, an cohort method study and a prediction study that are related as
they all use the same cohorts, then you may want to view the results in
a single shiny app. This can be done by using
ShinyAppBuilder
to combine the characterization, cohort
method and prediction shiny modules in OhdsiShinyModule
.
The main source of shiny modules is the OhdsiShinyModule
R
package, however, it is possible to add modules from other R
packages.
In this vignette we provide examples on how to use the
ShinyAppBuilder
to create flexible shiny apps for exploring
OHDSI results.
The ShinyAppBuilder
requires that all results be
explored by the shiny app are saved into a single database (i.e., all
results for the different shiny modules in an app are saved into the
same database), as a single database connection is shared across shiny
modules.
To create a shiny app that contains four shiny modules:
All of these are available as shiny modules in
OhdsiShinyModules
.
To create the shiny app via ShinyAppBuilder
we first
need to create a config specification for all the shiny modules we wish
to include into the single shiny app. A config can be created using
createModuleConfig
.
Inputs | Description |
---|---|
moduleId | a unique id for the shiny app |
tabName | The menu text for the module |
shinyModulePackage | The R package that contains the shiny module |
moduleUiFunction | The name of the module’s UI function |
moduleServerFunction | The name of the module’s server function |
moduleInfoBoxFile | The function in the shinyModulePackage package that contains the helper information |
moduleIcon | An icon to use in the menu for this module |
Note: it is possible to add shiny modules from any R package by
setting shinyModulePackage
to the R package with the UI and
server functions and then specifying the UI function as
moduleUiFunction
and server function as
moduleServerFunction
. However, the server function must
take as input id
(the module id as standard for shiny
server modules) and resultDatabaseSettings
(a list
containing the database result details required when extracting the
results from the database).
For the about module we will use the about shiny modules in
OhdsiShinyModule
. The UI is named aboutViewer
,
the server is named aboutServer
and the about helper
function is called aboutHelperFile()
. As the about module
provides information about the shiny app, the ‘info’ icon seems
appropriate. The inputs into createModuleConfig
for an
about module are:
aboutModule <- createModuleConfig(
moduleId = 'about',
tabName = "About",
shinyModulePackage = "OhdsiShinyModule",
moduleUiFunction = 'aboutViewer',
moduleServerFunction = 'aboutServer',
moduleInfoBoxFile = "aboutHelperFile()",
moduleIcon = 'info'
)
For simplicity, the ShinyAppBuilder
contains a function
called createDefaultAboutConfig
with these default about
settings into createModuleConfig
, this is quicker to use
than createModuleConfig
if you are using a standard about
module. Alternatively, you could just run:
aboutModule <- createDefaultAboutConfig()
To add a prediction module you can the OhdsiShinyModule
functions: aboutPrediction
for the module UI,
aboutPrediction
for the module server and
aboutPredictionFile()
for the about helper function. A
suitable icon is chart-line
. For the prediction module,
results in the database format created by the
PatientLevelPrediction
package must be in a database that
will be connected to when viewing the shiny app.
predictionModule <- createModuleConfig(
moduleId = 'prediction',
tabName = "Prediction",
shinyModulePackage = 'OhdsiShinyModules',
moduleUiFunction = "predictionViewer",
moduleServerFunction = "predictionServer",
moduleInfoBoxFile = "predictionHelperFile()",
moduleIcon = "chart-line"
)
For simplicity, the ShinyAppBuilder
contains a function
called createDefaultPredictionConfig
with these default
prediction settings. Atlernatively, you could just run:
predictionModule <- createDefaultPredictionConfig()
We have default config creation for cohort method and cohort
generation in ShinyAppBuilder
:
cohortMethodModule <- createDefaultEstimationConfig()
cohortGeneratorModule <- createDefaultCohortGeneratorConfig()
Next step is to combine the module config settings into a shiny app
config. First we use initializeModuleConfig()
to create an
empty shiny app config and then we use addModuleConfig()
to
add each of the module configs we previously created:
library(dplyr)
shinyAppConfig <- initializeModuleConfig() %>%
addModuleConfig(aboutModule) %>%
addModuleConfig(cohortGeneratorModule) %>%
addModuleConfig(cohortMethodModule) %>%
addModuleConfig(predictionModule)
It is possible to save the shiny app config using
saveConfig(shinyAppConfig, 'save location')
and load a
previously saved shiny app config
shinyAppConfig <- loadConfig('save location')
To run the shiny app on a shiny server, specify the connection details to the result database and then just add the following lines of code
# create a connection to the result database
connectionDetails <- DatabaseConnector::createConnectionDetails()
createShinyApp(shinyAppConfig, connectionDetails = connectionDetails)
To just view the shiny app locally, specify the connection details to the result database and then just add the following lines of code
# create a connection to the result database
connectionDetails <- DatabaseConnector::createConnectionDetails()
viewShiny(shinyAppConfig, connectionDetails = connectionDetails)
library(ShinyAppBuilder)
library(dplyr)
aboutModule <- createModuleConfig(
moduleId = 'about',
tabName = "About",
shinyModulePackage = "OhdsiShinyModule",
moduleUiFunction = 'aboutViewer',
moduleServerFunction = 'aboutServer',
moduleInfoBoxFile = "aboutHelperFile()",
moduleIcon = 'info'
)
predictionModule <- createModuleConfig(
moduleId = 'prediction',
tabName = "Prediction",
shinyModulePackage = 'OhdsiShinyModules',
moduleUiFunction = "predictionViewer",
moduleServerFunction = "predictionServer",
moduleInfoBoxFile = "predictionHelperFile()",
moduleIcon = "chart-line"
)
cohortMethodModule <- createDefaultEstimationConfig()
cohortGeneratorModule <- createDefaultCohortGeneratorConfig()
# add the modules into a single shiny config
shinyAppConfig <- initializeModuleConfig() %>%
addModuleConfig(aboutModule) %>%
addModuleConfig(cohortGeneratorModule) %>%
addModuleConfig(cohortMethodModule) %>%
addModuleConfig(predictionModule)
# add connection details to result database
connectionDetails <- DatabaseConnector::createConnectionDetails()
viewShiny(shinyAppConfig, connectionDetails = connectionDetails)