I have a Shiny app with the following structure:
shinyUI(dashboardPage(title="Map",
dashboardHeader(title = tags$img(src="logo.png")),
dashboardSidebar(sidebarMenu(id = "totalTab",
menuItem("Users", tabName = "dashboard", icon = icon("user-circle")),
menuItem("Map", tabName = "cities", icon = icon("map-o")),
menuItem("Med", tabName = "med", icon = icon("building-o"), selected = TRUE),
menuItem("Data", tabName = "opdata", icon = icon("database"))
),
dashboardBody(tabItems(
tabItem(tabName = "dashboard", uiOutput("bodyuser")),
tabItem(tabName = "med", uiOutput("bodyoutput")),
tabItem(tabName = "cities", uiOutput("citiesout")),
tabItem(tabName = "opdata", uiOutput("dataout"))
))
))
The first I see when I open the app is tab item "med". Inside "med" I have a tabset called "TabMap". I want to update "TabMap" using URL like this:
observe({
query <- parseQueryString(session$clientData$url_search)
if (!is.null(query[['panelname']])) {
rv$rvpanel <- query[['panelname']]
updateTabsetPanel(session, "TabMap", selected = rv$rvpanel)
}
})
Or this:
observe({
query <- parseQueryString(session$clientData$url_search)
if (!is.null(query[['panelname']])) {
updateTabsetPanel(session, "TabMap", selected = query[['panelname']])
}
})
But neither works. How can I do that?
PD: rv$rvpanel is a reactive value...
Tabset:
output$bodyoutput <- renderUI({
box(title = "Map", width ="100%", status = "info", solidHeader = TRUE,
uiOutput("tabmap"))
})
output$tabmap <- renderUI({
tabsetPanel(id = "TabMap",
tabPanel(width = "100%", title = "Add", value="panel5", uiOutput("formdead")),
tabPanel(width = "100%", title = "Ours", value="panel1", uiOutput("mapdeadout")),
tabPanel(width = "100%", title = "Month", value="panel4", uiOutput("mapmonthout")),
tabPanel(width = "100%", title = "Map", value = "panel2", uiOutput("maplifeout")),
tabPanel(width = "100%", title = "History", value="panel3", uiOutput("formhist"))
)
})
You just missed one thing, to check if "TabMap"
is already rendered and available in the input before your observe code gets executed.
This codes below seem to work
observe({
if(any(names(input) == "TabMap")){
query <- parseQueryString(session$clientData$url_search)
if (!is.null(query[['panelname']])) {
rv$rvpanel <- query[['panelname']]
updateTabsetPanel(session, "TabMap", selected = rv$rvpanel)
}
}
})
observe({
if(any(names(input) == "TabMap")){
query <- parseQueryString(session$clientData$url_search)
if (!is.null(query[['panelname']])) {
updateTabsetPanel(session, "TabMap", selected = query[['panelname']])
}
}
})
Hope this helps!
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.