Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
607 views
in Technique[技术] by (71.8m points)

r - How to select a specific tabPanel in Shiny

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 :-)

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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")
    })  
})  

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...