Fred Hutch Cancer Center
ui
mtcars
penguins
usethis::create_package()
)<module_name>_server
and <module_name>_ui
for your module names<module_name>_demo
(makes it easier for testing)id
using NS()
functionns()
ns("x_var")
or ns("hist_plot")
id
as inputmoduleServer()
encapsulates your server codemoduleServer()
<module_name>_demo()
function"modules/module_demo_02/app.R"
Eric Nantz: Effective Use of Shiny modules in App development :::
# execute plot variable selection modules
plot1vars <- varselect_mod_server("plot1_vars") #returns a reactive
plot2vars <- varselect_mod_server("plot2_vars") #returns a reactive
# execute scatterplot module
res <- scatterplot_mod_server(
"plots",
dataset = ames,
plot1vars = plot1vars,
plot2vars = plot2vars)
scatterplot_mod_server
scatterplot_mod_server <- function(input,
output,
session,
dataset,
plot1vars,
plot2vars) {
plot1_obj <- reactive({
p <- scatter_sales(dataset, xvar = plot1vars$xvar(), yvar = plot1vars$yvar())
return(p)
})
plot2_obj <- reactive({
p <- scatter_sales(dataset, xvar = plot2vars$xvar(), yvar = plot2vars$yvar())
return(p)
})
output$plot1 <- renderPlot({
plot1_obj()
})
{rhino}
- framework for developing apps from Appsilon