【问题标题】:Shiny select go to different tabPanel using action button or something闪亮的选择使用操作按钮或其他东西转到不同的tabPanel
【发布时间】:2014-11-13 06:13:23
【问题描述】:

我为我的闪亮应用构建了以下模板。

      ##ui.R
      shinyUI(navbarPage("My Application",
      tabPanel
      (
        "Select Data range",
        sidebarLayout
        (
            sidebarPanel
            (
                h3("Select Data Range"),
                selectInput("select", label = h3("Select Sector"),choices = list("Sector 1" = 1, "Sector 2" = 2,"Sector 3" = 3), selected = 1),br(),
                dateRangeInput("dates", label = h3("Select Date range")),br(),
                submitButton("Submit"),br(),
                actionButton("action", label = "Proceed to select resolution")
            ),
            mainPanel("Output")
        )
      ),

      tabPanel
      (
        "Select Resolution",
        sidebarLayout
        (
            sidebarPanel
            (
                h3("Select Resolution"),
                numericInput("num", label = h3("Select X-Grid Size"), value = 2),br(),
                numericInput("num", label = h3("Select Y-Grid Size"), value = 2),br(),
                numericInput("num", label = h3("Outlier Removal"), value = 2),br(),
                numericInput("num", label = h3("Frequency"), value = 2),br(),
                submitButton("Submit"),br(),
                #actionButton("action", label = "Proceed to Service Parameters")
            ),
            mainPanel("Output")
        )
      )

    ))

服务器文件暂时为空:

      ##server.R
      shinyServer(function(input, output) {
      })

理想情况下,我想在第一个 tabPanel 上使用类似操作按钮的输入来导航到第二个选项卡面板。任何关于替代方案的建议都将受到同样的赞赏。

【问题讨论】:

    标签: r shiny shiny-server


    【解决方案1】:

    您可以发送自定义消息:

    ui.R

    shinyUI(navbarPage("My Application",
    
                   tabPanel
                   (
                     "Select Data range",
                     sidebarLayout
                     (
                       sidebarPanel
                       (tags$head(tags$script('
                                         Shiny.addCustomMessageHandler("myCallbackHandler",
                                           function(typeMessage) {console.log(typeMessage)
                                              if(typeMessage == 1){
                                              console.log("got here");
                                              $("a:contains(Select Resolution)").click();
                                              }
                                              if(typeMessage == 2){
                                              $("a:contains(Select Data range)").click();
                                              }
                                              });
                                              ')),
                         h3("Select Data Range"),
                         selectInput("select", label = h3("Select Sector"),choices = list("Sector 1" = 1, "Sector 2" = 2,"Sector 3" = 3), selected = 1),br(),
                         dateRangeInput("dates", label = h3("Select Date range")),br(),
                         actionButton("action", label = "Proceed to select resolution")
                       ),
                       mainPanel("Output")
                     )
                   ),
    
                   tabPanel
                   (
                     "Select Resolution",
                     sidebarLayout
                     (
                       sidebarPanel
                       (
                         h3("Select Resolution"),
                         numericInput("num1", label = h3("Select X-Grid Size"), value = 2),br(),
                         numericInput("num2", label = h3("Select Y-Grid Size"), value = 2),br(),
                         numericInput("num3", label = h3("Outlier Removal"), value = 2),br(),
                         numericInput("num4", label = h3("Frequency"), value = 2),br(),
                         actionButton("action1", label = "Proceed to Service Parameters")
    
                       ),
                       mainPanel("Output"),
    
                     )
                   )
    
    ))
    

    服务器.R

    library(shiny)
    shinyServer(function(input, output,session) {
      observe({
        if(input$action > 0){
          print('1')
          session$sendCustomMessage("myCallbackHandler", "1")
        }
      })
      observe({
        if(input$action1 > 0){
          print('2')
          session$sendCustomMessage("myCallbackHandler", "2")
        }
      })
    }
    )
    

    此外,您不能拥有具有相同 ID 的对象。请注意,您所有的 numericInputactionButton 都有相同的 ID。我还删除了提交按钮,不确定您是否想要其中一个以上。

    【讨论】:

    • 谢谢,这正是我所需要的。这些对象具有相同的 ID,因为这只是应用程序的基本布局,我将在 server.R 中使用它们时重命名它们。
    猜你喜欢
    • 2012-04-12
    • 1970-01-01
    • 1970-01-01
    • 2021-06-27
    • 1970-01-01
    • 1970-01-01
    • 2020-03-22
    • 2017-10-12
    • 2016-09-12
    相关资源
    最近更新 更多