可复制代码如下。我有一个有几个标签的闪亮应用程序,其中包括一个"home"标签。选项卡。在"主页"选项卡上,我想包含一个链接到"标签2"的框。这意味着当单击该框时,它会将用户带到Tab 2。此外,我还希望当用户将鼠标悬停在该框上时,该框能做一些高亮显示,以便更容易识别出该框是指向某些内容的超链接。我该怎么做呢?
library(tidyverse)
library(DT)
library(shiny)
library(shinydashboard)
library(shinyWidgets)
ui <- navbarPage(
useShinydashboard(),
tabPanel(
title = "Home",
box(
title = "Box to link to tab2",
status = "primary",
width = 3
)
),
tabPanel(
title = "Tab 1"
),
tabPanel(
title = "Tab 2",
dataTableOutput("mtcars_table")
)
)
server <- function(input, output) {
output$mtcars_table <- DT::renderDataTable({mtcars})
}
shinyApp(ui, server)
是的,我已经看到了几个与此相关的例子,但我似乎无法使它们适用于这个特殊情况。
您可以使用actionLink
和updateTabItems
。请检查以下内容:
library(DT)
library(shiny)
library(shinydashboard)
library(shinyWidgets)
ui <- navbarPage(
useShinydashboard(),
tabPanel(
title = "Home",
box(
title = actionLink("tab2link", label = "Box to link to tab2"),
status = "primary",
width = 3
)
),
tabPanel(
title = "Tab 1"
),
tabPanel(
title = "Tab 2",
dataTableOutput("mtcars_table")
),
id = "navbar_id"
)
server <- function(input, output, session) {
observeEvent(input$tab2link, {
updateTabItems(session, inputId = "navbar_id", selected = "Tab 2")
})
output$mtcars_table <- DT::renderDataTable({mtcars})
}
shinyApp(ui, server)