This is a follow up of this question: How to pass values from ui to server in a shiny module
In the minimum working example below of an R Shiny Module, I can use the function send_value_to_server()
to send a value from UI to SERVER.
However, I cannot find a way to send more complex data structures like a dataframe, is there a way to do that?
library(shiny)
module_ui <- function(id, value_to_send) {
ns <- shiny::NS(id)
send_value_to_server <- function(id, value) {
shiny::selectInput(
inputId = id,
label = "If you can see this, you forgot shinyjs::useShinyjs()",
choices = value,
selected = value,
multiple=TRUE
) |> shinyjs::hidden()
}
shiny::tagList(
shinyjs::useShinyjs(), # Set up shinyjs
send_value_to_server(id = ns("value_to_send"), value = value_to_send),
shiny::verbatimTextOutput(ns("text_out"))
)
}
module_server <- function(id) {
moduleServer(id, function(input, output, session) {
value_received <- reactive(input$value_to_send)
output$text_out <- renderPrint({
paste("value passed from ui to server:", value_received())
})
})
}
ui <- fluidPage(
module_ui("test", value_to_send = 10)
)
server <- function(input, output, server) {
module_server("test")
}
shinyApp(ui, server)