Externally link to specific tabPanel in Shiny App

后端 未结 2 711
旧时难觅i
旧时难觅i 2021-01-03 10:44

It\'s possible to use anchor links in flat Shiny apps relatively easily - https://stackoverflow.com/a/28605517/1659890.

However, is it possible for an external link

相关标签:
2条回答
  • 2021-01-03 11:16

    I found the other answer a little difficult to follow so I created the example below. To navigate to the Data Availability tab, place "?a=b" to at the end of your url. For example if hosting the app on port 7436 the following link will take you directly to the Data Availability page. http://127.0.0.1:7436/?a=b

    library(shinydashboard)
    library(shiny)
    ui <- dashboardPage(
      dashboardHeader(),
      dashboardSidebar(
        sidebarMenu(id = "container",
          menuItem("Channels", tabName = "lt_channels"),
          menuItem("Data Availability", tabName = "data_avail")
        )),
      dashboardBody(
        tabItems(
          tabItem(tabName = "lt_channels",
                  h1("Test Fail")),
          tabItem(tabName = "data_avail",
                  h1("Test Pass"))
        )
      )
    )
    
    
    
    server <- function(session, input, output){
      observe({
        query <- parseQueryString(session$clientData$url_search)
        query1 <- paste(names(query), query, sep = "=", collapse=", ")
        print(query1)
        if(query1 == "a=b"){
          updateTabItems(session, inputId = "container", selected = "data_avail")
        }
      })
    }
    shinyApp(ui = ui, server = server)
    
    0 讨论(0)
  • 2021-01-03 11:39

    You could add a search query parameter to the URL (eg. href='www.myapp.com?tab=tab2), and in the app that is being linked you would have to add a bit of logic that changes to a specified tab on initialization if the search string is present (eg. look at session$clientData$url_search and if it exists and there's a tab variable, then use updateTabsetPanel() to go to that tab)

    0 讨论(0)
提交回复
热议问题