Shiny - updateTabsetPanel - 更改客户端上的选定选项卡

Shiny - updateTabsetPanel - Change the selected tab on the client

在应用程序的主页上,我们有 2 个 valueBox。我需要的是使它们可点击(作为按钮工作)并在点击事件时跳转到 tabpanel。

我需要的是单击“主页”选项卡上的“Title1”值框,它应该将屏幕重定向(导航)到“Tab1”屏幕上的“摘要”选项卡面板。

library(shiny)
library(shinythemes)
library(shinydashboard)
library(shinyWidgets)

ui <- navbarPage(
  theme = shinytheme("superhero"),
  title = "TabPanel",
  header = tagList(
    useShinydashboard()
  ),
  tabPanel(title = "Home",
           fluidRow(
             box(
               title = "ValuBox",
               width = 12,
               status = "info",
               solidHeader = T,
               valueBoxOutput("ibox"),
               valueBoxOutput("vbox")
             )
           )
  ),
  tabPanel(title = "Tab1",
           tabsetPanel(
             tabPanel("Plot"),
             tabPanel("Summary"),
             tabPanel("Table")
           )),
  tabPanel(title = "Tab2",
           tabsetPanel(
             tabPanel("BarChart"),
             tabPanel("SummaryTable"),
             tabPanel("TableDT")
           ))
)

server <- function(input, output) {
  output$ibox <- renderValueBox({
    valueBox(
      value = "Title1",
      subtitle = "Text1",
      color = "aqua",
      icon = icon("credit-card")
    )
  })
  output$vbox <- renderValueBox({
    valueBox(
      value = "Title2",
      subtitle = "Text2",
      color = "light-blue",
      icon = icon("credit-card")
    )
  })
}

shinyApp(ui, server)

编辑:我没有正确阅读您的问题。我修改了代码以满足您关于将选项卡 1 的内部选项卡更新为摘要的请求。

ui 对象中,您可以将输出包装在 actionLink 中,然后将观察者附加到使用 updateTabsetPanel 更新选项卡的 link。但是,首先您需要一个 id 用于整个 navbarPage。我对您的代码进行了必要的更改,以便通过按第一个 valueBox,将您发送到 Tab1。我在添加行的地方添加了评论。

library(shiny)
library(shinythemes)
library(shinydashboard)
library(shinyWidgets)

ui <- navbarPage(
  id = "tabset", # NEW ID
  theme = shinytheme("superhero"),
  title = "TabPanel",
  header = tagList(
    useShinydashboard()
  ),
  tabPanel(title = "Home",
           fluidRow(
             box(
               title = "ValuBox",
               width = 12,
               status = "info",
               solidHeader = T,
               actionLink( #WRAPPED VALUEBOX IN ACTIONLINK
                 inputId = "link1",
                 label = HTML(
                   as.character(valueBoxOutput("ibox"))
                 )
                 
               ),
               valueBoxOutput("vbox")
             )
           )
  ),
  tabPanel(title = "Tab1",
           value = "tab1", #ADDED A VALUE PARAMETER HERE
           tabsetPanel(
             id = "tab1_inner", #ADDED ID HERE
             tabPanel("Plot"),
             tabPanel("Summary"),
             tabPanel("Table")
           )),
  tabPanel(title = "Tab2",
           value = "tab2", #ADDED A VALUE PARAMETER HERE
           tabsetPanel(
             id = "tab2_inner", #ADDED ID HERE
             tabPanel("BarChart"),
             tabPanel("SummaryTable"),
             tabPanel("TableDT")
           ))
)

server <- function(input, output) {
  output$ibox <- renderValueBox({
    valueBox(
      value = "Title1",
      subtitle = "Text1",
      color = "aqua",
      icon = icon("credit-card")
    )
  })
  output$vbox <- renderValueBox({
    valueBox(
      value = "Title2",
      subtitle = "Text2",
      color = "light-blue",
      icon = icon("credit-card")
    )
  })
  
  observeEvent(input$link1, { #OBSERVER THAT CHANGES TAB WHEN LINK IS CLICKED
    updateTabsetPanel(inputId = "tabset", selected = "tab1")
    updateTabsetPanel(inputId = "tab1_inner", selected = "Summary")
  })
 
}

shinyApp(ui, server)