how pass multiple parameters to shiny app via URL to updateSelectInput?

有些话、适合烂在心里 提交于 2021-01-07 01:21:48

问题


I have this code for "global" query for passing multiple arguments (countries) to show multiple plot via updateSelectInput

my project http://webcovid19.online

Problem is that parameter passing is working only for 1 argument like this http://webcovid19.online/?global=Slovakia, with more arguments like below http://webcovid19.online/?global=Slovakia,Czechia looks that passing arguments not working, got this error. "Aesthetics must be either length 1 or the same as the data (1): x, y, colour, label and group"

server <- function(input, output, session) {
session$clientData$url_search
  observe({
    query <- parseQueryString(session$clientData$url_search)
    if (!is.null(query[['global']])) {
       updateSelectInput(session, "country_input", selected = query[['global']])
      updateNavbarPage(session, "mainNavbarPage", selected="COVID 19 Global Stats")

    }

  })

UI

   selectInput("country_input", "Countries:",
                              unique(countries$country),
                              selected = start_countries,
                              multiple = TRUE),

DF for countries

head (countries)
  country  confirmed
1      US 1682183074
2   India 1063726855
3  Brazil  875580392

Any idea please ? When I did debug, I can see both parameters but how to pass to my app ? Looks that I have to parse somehow.

query[['global']]
[1] "Slovakia,Czechia" 

str(query[["global"]])
 chr "Slovakia,Czechia"

回答1:


Shiny App: How to Pass Multiple Tokens/Parameters through URL

The standard delimeter for tokens passed through url to shiny app is the & symbol.

Example shiny app code:

server <- function(input, output, session) {
  observe({
    query <- parseQueryString(session$clientData$url_search)
    if (!is.null(query[['paramA']])) {
        updateTextInput(session, "InputLabel_A", value = query[['paramA']])
    }
    if (!is.null(query[['paramB']])) {
        updateTextInput(session, "InputLabel_A", value = query[['paramB']])
    }
  })
  # ... R code that makes your app produce output ..
}

Coresponding URL example: http://localhost.com/?paramA=hello&?paramB=world

Reference: parseQueryString Docs

Although it seems as though your question is how to parse string tokens from a single passed paramater, no? Decided to include this answer anyway because this was the first result on google for how to pass multiple params through url to shiny app and I'm sure others will find useful.



来源:https://stackoverflow.com/questions/65520716/how-pass-multiple-parameters-to-shiny-app-via-url-to-updateselectinput

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!