This should be pretty straight forward for most people. I'm trying to return two data sets from a shiny module for use in a main app. Below is a contrived example. I'd like to to return iris
and mtcars
and then just display mtcars
in my example in the main app. I have a reference dataset of BOD
in the module's UI as well as just a base case. Any advice would be much appreciated!
mtcarsUI <- function(id) {
ns <- NS(id)
tagList(
verbatimTextOutput(ns('out'))
)
}
mtcarsServer <- function(id) {
moduleServer(id, function(input, output, session) {
output$out <- renderPrint(BOD)
# This isn't being returned properly
list(mtcars_data= reactive({mtcars}),
iris_data = reactive({iris})
)
})
}
mtcarsApp <- function() {
ui <- fluidPage(
mtcarsUI('test'),
verbatimTextOutput('mtcars_out')
)
server <- function(input, output, session) {
datasets <- mtcarsServer('test')
# if I set 'datasets' as a reactive i.e. datasets() I get an error.
# If I keep 'datasets' as is, it returns that it's a reactive object, but not the value
output$mtcars_out <- renderPrint(datasets()$mtcars_data)
}
shinyApp(ui, server)
}
mtcarsApp()