How do you pass parameters to a shiny app via URL

后端 未结 2 1091
抹茶落季
抹茶落季 2020-11-30 01:46

In web browsers you pass parameters to a website like

www.mysite.com/?parameter=1

I have a shiny app and I would like to use the parameter passed in to the s

2条回答
  •  忘掉有多难
    2020-11-30 02:41

    You'd have to update the input yourself when the app initializes based on the URL. You would use the session$clientData$url_search variable to get the query parameters. Here's an example, you can easily expand this into your needs

    library(shiny)
    
    shinyApp(
      ui = fluidPage(
        textInput("text", "Text", "")
      ),
      server = function(input, output, session) {
        observe({
          query <- parseQueryString(session$clientData$url_search)
          if (!is.null(query[['text']])) {
            updateTextInput(session, "text", value = query[['text']])
          }
        })
      }
    )
    

提交回复
热议问题