【问题标题】:How to select a specific tabPanel in Shiny如何在 Shiny 中选择特定的 tabPanel
【发布时间】:2016-08-23 05:43:09
【问题描述】:

我正在尝试在简单的 Shiny 应用程序中动态选择特定的 tabPanel。 app的脚本如下:

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

这个想法是按下按钮“goButton_service”并选择tabPanel “Download & Binning input data”

我使用了这里的示例 R Shiny switch tabPanel when selectInput value changes

但是 tabPanel 没有被选中。非常感谢您的帮助:-)

【问题讨论】:

    标签: r shiny


    【解决方案1】:

    问题是您的 UI 中没有 tabsetPanel(它应该是两个 tabPanel 的父级)。现在你使用的是updateTabsetPanel,但目标是navbarPage

    下面的工作解决方案。有两个问题:navbarPage 需要一个id,而且server.R 中有一个额外的空间selected(在Binning 和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"
        )
    )
    )
    

    服务器.R

    图书馆(闪亮)

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

    【讨论】:

    • 感谢您的评论。我已经考虑到你的暗示了。我使用了' updateNavbarPage(session, "ScoreDevApp", selected = "Download & Binning input data") '。但是仍然没有结果 - 没有选择目标面板。 P.S.:shiny.rstudio.com/reference/shiny/latest/updateTabsetPanel.html 表示 'updateNavbarPage' 用于选择指定的面板。
    猜你喜欢
    • 2016-01-06
    • 2016-07-21
    • 2016-07-13
    • 1970-01-01
    • 1970-01-01
    • 2019-01-24
    • 1970-01-01
    • 2014-06-08
    • 1970-01-01
    相关资源
    最近更新 更多