在闪亮的模块中使用省略号

Usage of ellipsis within a shiny module

我想知道是否可以在闪亮的服务器模块中使用省略号 (...)。我认为问题是我无法在服务器模块中调用反应值(因为它通常用括号 - value() 完成)。

尝试使省略号具有反应性 ...() 也没有成功。有人知道如何解决这个问题吗?

提前致谢!

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)

您可以使用 list 将省略号转换为列表,然后使用 lapplydo.call 调用您的函数。我稍微更改了您的示例以展示如何将输入从 ui 传递到函数。

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}))
  }
)