【问题标题】:Dynamic name for ggvisoutput in ShinyShiny 中 ggvisoutput 的动态名称
【发布时间】:2018-06-16 08:19:14
【问题描述】:

假设我在服务器中有以下代码:

df%>%
  ggvis(~ratio, ~height, fill = ~ps, key := ~id) %>% 
  layer_bars() %>%
  bind_shiny('rds', 'ui_rds')

还有如下的ui:

fluidRow( box(title = "RD",width = 6, ggvisOutput('rds')))

问题是如果输出的名称是可变的并且随时间变化, 如何在 ui 中设置?

换句话说,如果服务器的代码如下:

x <<- "some value which will be changed reactively"
df%>%
  ggvis(~ratio, ~height, fill = ~ps, key := ~id) %>% 
  layer_bars() %>%
  bind_shiny(x, paste('ui_',x))

ui 的代码应该是什么?

【问题讨论】:

    标签: r shiny ggvis


    【解决方案1】:

    我不明白您为什么要这样做,但renderUI 始终可以处理动态IDs。

    在下面的示例中,ggvis::bind_shiny 中的 plot_id 参数将由 textInput 创建。 renderUI/uiOutput 用于将情节“引导”到单个 id "plot_wrapped"

    library(ggvis)
    library(shiny)
    
    shinyApp(
      fluidPage(
        textInput("plot_id", value = "some_id",
                  "choose plot id (avoid spaces and special characters)"),
        uiOutput("plot_wrapped")
      ),
      function(input, output, session){
        observe({
          mtcars %>% ggvis(~mpg, ~wt) %>% layer_points() %>%
            bind_shiny(input$plot_id)
        })
    
        output$plot_wrapped <- renderUI({
          ggvisOutput(input$plot_id)
        })
      }
    )
    

    如上所述,我建议不要在shiny 中使用动态ID,除非确实有必要。

    【讨论】:

      猜你喜欢
      • 2019-04-06
      • 1970-01-01
      • 2011-12-03
      • 2020-04-13
      • 2015-05-11
      • 1970-01-01
      • 2022-11-22
      • 1970-01-01
      • 2015-01-23
      相关资源
      最近更新 更多