【问题标题】:Usage of ellipsis within a shiny module在闪亮的模块中使用省略号
【发布时间】:2018-01-30 17:00:40
【问题描述】:

我想知道,是否可以在闪亮的服务器模块中使用省略号 (...)。我认为问题是我不能在服务器模块中调用反应值(因为它通常用括号完成 - 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)

【问题讨论】:

    标签: module shiny ellipsis


    【解决方案1】:

    您可以使用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}))
      }
    )
    

    【讨论】:

      猜你喜欢
      • 2021-01-10
      • 2017-12-09
      • 2019-10-20
      • 2020-01-18
      • 2019-01-18
      • 2021-07-17
      • 1970-01-01
      • 2018-05-11
      • 2023-04-09
      相关资源
      最近更新 更多