1
可以在一个链接中使用tabPanel ID?我讲的ID喜欢#标签-6584-1或#标签-6985-1,显示当你的光标悬停在一个闪亮的应用程序选项卡浏览器中运行:如何捕捉Shiny应用中的动态tabPanel()ID
Image of dynamic tabPanel() id example with Firefox
我想要使用此功能将Shiny应用中的左上角链接置于应用“主页”页面上进行重定向。
可以在一个链接中使用tabPanel ID?我讲的ID喜欢#标签-6584-1或#标签-6985-1,显示当你的光标悬停在一个闪亮的应用程序选项卡浏览器中运行:如何捕捉Shiny应用中的动态tabPanel()ID
Image of dynamic tabPanel() id example with Firefox
我想要使用此功能将Shiny应用中的左上角链接置于应用“主页”页面上进行重定向。
从你的问题,我不确定,但它似乎是你想模仿导航到你的应用程序中的“子页面”。如果是这样的话,可以通过在应用的URL末尾读取和写入哈希字符串的值来做到这一点(link to gist):
library(shiny)
ui <- fluidPage(
sidebarLayout(
sidebarPanel(
tags$a("Go to Panel 1", href = "#panel1"), br(),
tags$a("Go to Panel 2", href = "#panel2"), br(),
tags$a("Go to Panel 3", href = "#panel3")
),
mainPanel(
tabsetPanel(id = "tabs",
tabPanel("Panel 1", h1("Panel 1"), value = "#panel1"),
tabPanel("Panel 2", h1("Panel 2"), value = "#panel2"),
tabPanel("Panel 3", h1("Panel 3"), value = "#panel3")
)
)
)
)
server <- function(input, output, session) {
# When we change from one `tabPanel` to another, update the URL hash
observeEvent(input$tabs, {
# No work to be done if input$tabs and the hash are already the same
if (getUrlHash() == input$tabs) return()
# The 'push' argument is necessary so that the hash change event occurs and
# so that the other observer is triggered.
updateQueryString(
paste0(getQueryString(), input$tabs),
"push"
)
# Don't run the first time so as to not generate a circular dependency
# between the two observers
}, ignoreInit = TRUE)
# When the hash changes (due to clicking on the link in the sidebar or switching
# between the `tabPanel`s), switch tabs and update an input. Note that clicking
# another `tabPanel` already switches tabs.
observeEvent(getUrlHash(), {
hash <- getUrlHash()
# No work to be done if input$tabs and the hash are already the same
if (hash == input$tabs) return()
valid <- c("#panel1", "#panel2", "#panel3")
if (hash %in% valid) {
updateTabsetPanel(session, "tabs", hash)
}
})
}
shinyApp(ui, server)