在應用程式的主頁上,我們有 2 個 valueBox。我需要的是使它們可點擊(作為按鈕作業)并在點擊事件時跳轉到標簽面板。
我需要的是單擊主頁選項卡上的“Title1”valueBox,它應該將螢屏重定向(導航)到“Tab1”螢屏上的“Summary”tabPanel。


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)
uj5u.com熱心網友回復:
編輯:我沒有正確閱讀您的問題。我已修改代碼以滿足您關于將選項卡 1 的內部選項卡更新為摘要的請求。
在ui物件中,您可以將輸出包裝在 a 中actionLink,然后將觀察者附加到使用 更新選項卡的鏈接updateTabsetPanel。但是,首先您需要一個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)
轉載請註明出處,本文鏈接:https://www.uj5u.com/qiye/480419.html
