[英]How to direct HTML links to siderbar items in R Shiny
我正在尝试在我的 Shiny 仪表板中添加一个 HTML 链接。 理想的解决方案是通过单击侧栏上的项目将用户定向到网站。 但是,我找不到这样做的解决方案。
这是我的代码:
library(shiny)
library(shinydashboard)
header <- dashboardHeader(
title = "Test Dashboard"
)
sidebar <- dashboardSidebar(
sidebarMenu (
menuItem("Test",startExpanded = TRUE,
menuSubItem("Dashboard", tabName = "tab"),
menuSubItem("Link")
)
)
)
body <- dashboardBody(
tabItems(
tabItem(tabName = "tab",
box(title = "Table", width = 10, status = "warning", DT::dataTableOutput("table"))
)
)
)
ui <- dashboardPage(header, sidebar, body)
server <- function(input, output) {
output$table = DT::renderDataTable({
DT::datatable(tabledata)
})
}
shiny::shinyApp(ui, server)
这是当前的侧边栏布局。
目前,我只在仪表板选项卡中显示数据表,在链接选项卡中没有显示。
我想知道是否可以通过单击侧边栏上的选项卡名称“链接”将用户重定向到网站 ( https://shiny.rstudio.com/ )。
我知道解决方案可能是在Server 中呈现 HTML 链接并在UI 中输出。 请指教。
提前致谢。
请参阅?menuSubItem
它有一个href
参数:
library(shiny)
library(shinydashboard)
header <- dashboardHeader(
title = "Test Dashboard"
)
sidebar <- dashboardSidebar(
sidebarMenu (
menuItem("Test",startExpanded = TRUE,
menuSubItem("Dashboard", tabName = "tab"),
menuSubItem(text = "Link", href = "https://shiny.rstudio.com/")
)
)
)
body <- dashboardBody(
tabItems(
tabItem(tabName = "tab",
box(title = "Table", width = 10, status = "warning", DT::dataTableOutput("table"))
)
)
)
ui <- dashboardPage(header, sidebar, body)
server <- function(input, output) {
tabledata <- data.frame(replicate(10, sample(runif(10, 1, 10), rep=TRUE)))
output$table = DT::renderDataTable({
DT::datatable(tabledata)
})
}
shiny::shinyApp(ui, server)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.