I wonder, if it is possible to use ellipsis (...) in a shiny server module. I think the problem is that i cannot call the reactive value (as it is usual done with parentheses - value() ) within the server module.
Trying to make the ellipsis reactive ...() did also not work out. Anyone an idea how to solve this issue?
Thanks in advance!
renderPlotsUI = function(id) {
ns = NS(id)
tagList(plotOutput(ns("plot")))
}
renderPlots = function(input, output, session, FUN, ...) {
output$plot = renderPlot({FUN(...)})
}
# APP BEGINS
ui = fluidPage(
renderPlotsUI("plot1")
)
server = function(input, output, session) {
callModule(renderPlots, "plot1", FUN=plot, x = reactive(mtcars))
}
shinyApp(ui, server)
You can convert the ellipsis to a list with list
and then use lapply
and do.call
to call your function. I slightly changed your example to showcase how to pass inputs from the ui
to the function.
library(shiny)
renderPlotsUI = function(id) {
ns = NS(id)
tagList(plotOutput(ns("plot")))
}
renderPlots = function(input, output, session, FUN, ...) {
output$plot = renderPlot({
args_evaluated <- lapply(list(...), function(x){x()})
do.call(FUN, args_evaluated)
})
}
shinyApp(
fluidPage(
sliderInput("n", "n", 1, 10, 5),
renderPlotsUI("plot1")
) ,
function(input, output, session) {
callModule(renderPlots, "plot1", FUN = plot, x = reactive({1:input$n}))
}
)