2013-07-15 83 views
1

我使用闪亮来显示两种方法A和B的结果。首先,我使用radioButtons,以便最终用户可以选择其中一种方法,然后在列表中进一步指定下拉菜单中要显示的项目。由于有两种方法,我还考虑使用“制表符”(tabsetPanel)。我的问题是,有没有办法在点击方法的radioButton时,相应的“tabview”会自动切换(到所需方法的显示结果)?radioButton和tabsetPanel自动更改为R Shiny

谢谢!如果有一个类似于这种情况的实例,那将是非常好的。

回答

4

退房的帮助?updateTabsetPanel,或?conditionalPanel

如果你决定去updateTabsetPanel方法,您可以根据用户的输入有选择的选项卡的变化(直接从帮助中获取):

# in server.R 
shinyServer(function(input, output, session) { 
    observe({ 
     # TRUE if input$controller is even, FALSE otherwise. 
     x_even <- input$controller %% 2 == 0 

     # Change the selected tab. 
     # Note that the tabsetPanel must have been created with an 'id' argument 
     if (x_even) { 
      updateTabsetPanel(session, "inTabset", selected = "panel2") 
     } else { 
      updateTabsetPanel(session, "inTabset", selected = "panel1") 
     } 
    }) 
}) 

请注意使用session对象和?observe

如果你决定去conditionalPanel方法:

# in ui.R 
selectInput("method", "Method", c("A", "B")), 
conditionalPanel(
    condition = "input.method == 'A'", 
    plotOutput(...) # or whatever input/output you want 
), 
conditionalPanel(
    condition = "input.method == 'B'", 
    plotOutput(...) # or whatever input/output you want 
) 

我不相信conditionalPanel工程,使有条件的标签,但。 (我可能错了)