djx99me
djx99me

Reputation: 115

Generate HTML Link to Filtered SHINY Webpage

I have a Shiny app with a couple of filters so that I can choose various combinations of variables to display in a plot.

Let's say I have a selectInput filter called "car" that contains 3 types of cars - "Audi", "BMW" and "Toyota". When I navigate to the shiny app, the default selection is set to Audi (I know I can sort this list alphabetically etc.).

But is it possible to specify a html link directly to a particular filter option?

E.g. something like: https://myapp/cars="BMW"

I am not too familiar with web technologies but am hoping that there is someway to programmatically specify a direct link to filtered options in a Shiny app without having to manually select the filter option.

Thanks for reading.

Upvotes: 2

Views: 46

Answers (1)

zx8754
zx8754

Reputation: 56149

Here is an example app by Dean Attali at GitHub:

library(shiny)

ui <- fluidPage(
  textInput("name", "Name"),
  numericInput("age", "Age", 25)
)

server <- function(input, output, session) {
  observe({
    query <- parseQueryString(session$clientData$url_search)
    if (!is.null(query[['name']])) {
      updateTextInput(session, "name", value = query[['name']])
    }
    if (!is.null(query[['age']])) {
      updateNumericInput(session, "age", value = query[['age']])
    }
  })
}

shinyApp(ui, server)

enter image description here

Upvotes: 1

Related Questions