Getting URL parameters in a shiny dashboard app

Has anyone been successful in using URL parameters in a shiny dashboard app? I've experimented with the many posts and documentation for using the session$clientData$url_search string. I can get several simple examples to work but have not been able to access the url_search string from within the dashboard environment.

Hi,

Could you please provide us with a comprehensive example using the post below to let us reproduce the issue and see where you get stuck:

Thanks,
PJ

PJ,

In coming up with a simple example I managed to get this to work. Here's the example in case anyone else has the same trouble.

Tom

library(shiny)
library(shinydashboard)

ui <- dashboardPage(
  dashboardHeader(title="Query Parameters"),
  dashboardSidebar(),
  dashboardBody(
    h3("URL components"),
    verbatimTextOutput("urlText"),
    h3("Parsed query string"),
    verbatimTextOutput("queryText")
  )
)

server <- function(input, output, session) {
  
  # Return the components of the URL in a string:
  output$urlText <- renderText({
    paste(sep = "",
          "protocol: ", session$clientData$url_protocol, "\n",
          "hostname: ", session$clientData$url_hostname, "\n",
          "pathname: ", session$clientData$url_pathname, "\n",
          "port: ",     session$clientData$url_port,     "\n",
          "search: ",   session$clientData$url_search,   "\n"
    )
  })
  
  # Parse the GET query string
  output$queryText <- renderText({
    query <- parseQueryString(session$clientData$url_search)
    
    # Return a string with key-value pairs
    paste(names(query), query, sep = "=", collapse=", ")
  })
}

shinyApp(ui, server)

1 Like

If your question's been answered (even by you!), would you mind choosing a solution? It helps other people see which questions still need help, or find solutions if they have similar problems. Here’s how to do it:

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