Changing Landing Page/Tabs Depending on the URL

Hi all,

I have a Shiny issue; similar to this Stack Overflow discussion - https://stackoverflow.com/questions/33021757/externally-link-to-specific-tabpanel-in-shiny-app.

Essentially I want the landing page of my shiny app to change depending on the parameters present within the URL. So http://127.0.0.1:7436/?page=a=b would load into a different tab than if the /?page=a=b part was missing (sorry, as a new poster I can only include 2 links in my post).

I'm currently using a method similar to the one shown in this code (from the StackOverflow link above), whereby I update which TabItem is selected depending on the parameters which are pulled through by
parseQueryString(session$clientData$url_search)

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)type or paste code here

This approach sort of works in that it does load the correct tab. However, it first loads the 'default' home page, before redirecting to the appropriate tab after a couple of seconds. Essentially the 'observe' function takes a couple of seconds to kick in, as the rest of the app is loaded. This makes the app feel a lot less slick, and I'd like to to instead load straight into the correct tab. So rather than loading the default landing page and then updating it to the correct page, I'd like to land straight on the correct page.

Is this at all possible?

Thanks for any help!

This topic was automatically closed 54 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.