4

I am trying to select a specic tabPanel dynamically in the simply Shiny app. The script of app is as follows:

ui.r

library(shiny)
shinyUI(fluidPage(

  titlePanel("SCORE CARD DEVELOPMENT PLATFORM"),
    navbarPage("ScoreDevApp",
         tabPanel("Settings",
                  fluidRow(column(2,
                                  actionButton("goButton_service", "Load   saved parameters",width=200)
                                  )
                          )
         ),
         tabPanel("Download & Binning input data")
        )
)
)

server.r:

library(shiny)

shinyServer(function(input, output, session) {
  #load saved parameters 
  observeEvent(input$goButton_service, {
    updateTabsetPanel(session, "ScoreDevApp", selected = "Download & Binning  input data")
 })  
})  

The idea is to press the button "goButton_service" and select the tabPanel "Download & Binning input data".

I have used the example from here R Shiny switch tabPanel when selectInput value changes .

However the tabPanel is not selected. I would be very grateful for your help :-)

Community
  • 1
  • 1
Dimon D.
  • 438
  • 5
  • 23

1 Answers1

6

Problem is that you don't have a tabsetPanel in your UI (which should be the parent of the two tabPanel). Right now you are using updateTabsetPanel, but the target is navbarPage.

Working solution below. There were two problems: navbarPage needs an id, and also there was an extra space in server.R selected (between Binning and input`

ui.R

library(shiny)
shinyUI(fluidPage(

    titlePanel("SCORE CARD DEVELOPMENT PLATFORM"),
    navbarPage("ScoreDevApp",
               tabPanel("Settings",
                        fluidRow(column(2,
                                        actionButton("goButton_service", "Load   saved parameters",width=200)
                        )
                        )
               ),
               tabPanel("Download & Binning input data"),
               id="ScoreDevApp"
    )
)
)

server.R

library(shiny)

shinyServer(function(input, output, session) {
    #load saved parameters 
    observeEvent(input$goButton_service, {
        updateNavbarPage(session, "ScoreDevApp", selected = "Download & Binning input data")
    })  
})  
Xiongbing Jin
  • 11,779
  • 3
  • 47
  • 41
  • thanks for comment. I have taken into account your hint. I have used ' updateNavbarPage(session, "ScoreDevApp", selected = "Download & Binning input data") '. But there is still no results - the targeted panel is not selected. P.S.: http://shiny.rstudio.com/reference/shiny/latest/updateTabsetPanel.html is said that 'updateNavbarPage' is used to select the panel specified. – Dimon D. Apr 29 '16 at 07:06