How can I change tabsetPanel when clicking actionButton?

2,527 views
Skip to first unread message

Summer Rae

unread,
Aug 10, 2014, 10:42:57 PM8/10/14
to shiny-...@googlegroups.com
Hello-

In my main panel I have two tabs, one with a table, and one with a graph. The table tab is the default view, so when the user clicks on the actionButton titled "Graph" they currently then have to click on the "Graph" tab to view the results. I would like to have the actionButton automatically change focus to the Graph tab, but I am unable to find any documentation on how to access the output from the actionButton for the purpose. 

Here's what I have: 

ui.R

library(shiny)

# Define the overall UI
shinyUI(fluidPage(
    titlePanel("A.inornata gene expression during tail regeneration"),

    sidebarPanel(
        selectInput(inputId="measure", label="Select measurement:",
              choices = c("CPM by time point", "RPKM by time point", "CPM by sample", "RPKM by sample")),
    textInput(inputId="comp", label="Enter contig to graph:", value=""),
    helpText("To graph expression, enter the gene name and description here, then click the 'graph' button."),
    actionButton(inputId="graph.button", label="Graph", icon=NULL)

),#end sidepanel
        
   mainPanel(
       tabsetPanel(id="tabs",
       tabPanel(title="Table", value="panel1", dataTableOutput(outputId="table")),
       tabPanel(title="Graph", value="panel2", plotOutput("graph")))

           )
       ))         

server.R

    observe({
        #this doesn't even begin to work
         if input$graph.button == TRUE {
            updateTabsetPanel(session, "tabs", selected = "panel2")
        } else {
            updateTabsetPanel(session, "tabs", selected = "panel1")
        }
    })

I know it's way off, thanks in advance for any help! 

Summer Rae

unread,
Aug 11, 2014, 12:20:51 PM8/11/14
to shiny-...@googlegroups.com
I figured it out: 

 observe({
        # use tabsetPanel 'id' argument to change tabs
        if (input$graph.button > 0) {
            updateTabsetPanel(session, "tabs", selected = "panel2")
        } else {
            updateTabsetPanel(session, "tabs", selected = "panel1")
        }
    })

Reply all
Reply to author
Forward
0 new messages