R Shiny:从服务器端打开弹出窗口

时间:2017-01-26 22:10:37

标签: r shiny

我使用ShinyBS包中的bsModal指令在我的应用程序中打开弹出窗口。

我想使用这个弹出窗口绘制几个情节图,具体取决于我点击的输入按钮,但是因为我必须在引号之间返回图形名称,所以我没有成功。< / p>

这是我的UI代码的一部分:

tabItem(tabName = "Tab 1",
    useShinyjs(),

      bsModal("modal_graph", textOutput("graph_title"), textOutput("graph_name"), size = "large",
      fluidRow(plotlyOutput("graph_df", height = 700))),

我服务器的一部分:

observeEvent(input$btn_modal_graphCG,{

    graph_title <- paste("Housing class : ", CL1)
    output$graph_title <- renderText({graph_title})

    graph_name <- shQuote("btn_modal_graphCG")
    output$graph_name <- renderText({graph_name})

正如你所看到的,bsModal的第三个参数必须是输入模态按钮的名称:&#34; btn_modal_graphCG&#34;,所以我想我必须用双引号向Ui发送它,但我不是&# 39; t成功做到了。

你知道我怎么做吗?

非常感谢您的帮助。

编辑:我更改了帖子标题,我发现如何处理从服务器端打开弹出窗口的toggleModal命令:

在ui中,在dashboardBody打开行之后,我添加:

useShinyjs(),    
    bsModal("modal_graph", textOutput("graph_title"), "", size = "large",            
        fluidRow(              
          plotlyOutput("graph_df", height = graph_size)
) # end of fluidRow(

) # end of bsModal(

使用关联的操作按钮:

actionButton("btn_modal_graph_", "", width = 100, icon("bar-chart"), class = "btn_block", style = "color : #FFF ; background-color : #337ab7 ; border-color : #2e6da4")

服务器端:

observeEvent(input$btn_modal_graph,{
             .........
             .........
             output$graph_df <- renderPlotly({
             .........
             .........
                      }) # end of renderPlotly

toggleModal(session, "modal_graph", "open")

}) # end of observeEvent

度过愉快的一天。

0 个答案:

没有答案