切换闪亮的选项

时间:2016-10-17 13:40:53

标签: r shiny

在我闪亮的仪表板中,我有一个单选按钮,如下所示,

#circleSVG {
  fill: red;
  stroke: green;
}

#circleSVG.testCircle{
  fill: orange;
  opacity:0.25;
}

现在基于此单选按钮选择,我希望根据选择切换输出选项卡。意思是,如果我选择" Count"那么"伯爵"视图应该显示和"百分比"视图应该被禁用。

下面是我主要标签的代码

radioButtons("view", "View Type", c("Count", "Percent"), selected = "Count")

感谢任何帮助。

1 个答案:

答案 0 :(得分:3)

您可以使用updateTabsetPanel()函数。这是代码:

ui.R

    library(shiny)


    shinyUI(pageWithSidebar(


            headerPanel("Tabsets"),
            sidebarPanel(
                    radioButtons("view", "View Type:",
                                 c("Count", "Percent"), 
                                 selected = "Count")

            ),
            mainPanel(
                    tabsetPanel(id = "tab",
                                tabPanel(title = "Count of objects", 
                                         value = "countsOfObjects", 
                                         tableOutput("mon")),
                                tabPanel(title = "% of Objects", 
                                         value = "percentOfObjects", 
                                         tableOutput("mon_per")))

                    )
            )
    )

server.R

    library(shiny)

    shinyServer(function(input, output, session) {
            observeEvent(input$view, {
                    if (input$view == "Count") {
                            updateTabsetPanel(session, "tab",
                                              selected = "countsOfObjects"
                            )      
                    } else {
                            updateTabsetPanel(session, "tab",
                                              selected = "percentOfObjects"
                            )                         
                    }

            })

    })