如何通过 URL 将多个参数传递给 shiny app to updateSelectInput?

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

我有这个“全局”查询代码,用于传递多个参数(国家)以通过 updateSelectInput

显示多个图

我的项目http://webcovid19.online

问题是参数传递仅适用于像这样的 1 个参数 http://webcovid19.online/?global=Slovakia,还有更多 如下论点 http://webcovid19.online/?global=Slovakia,Czechia 看起来传递参数不起作用,出现此错误。 “美学必须是长度 1 或与数据 (1) 相同:x、y、颜色、标签和组”

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

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

有什么想法吗? 当我进行调试时,我可以看到这两个参数,但是如何传递给我的应用程序呢? 看来我必须以某种方式解析。

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

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

Shiny App:如何通过 URL

传递多个 Tokens/Parameters

通过 url 传递到闪亮应用程序的令牌的标准分隔符是 & 符号。

闪亮应用代码示例:

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 ..
}

对应URL例子: http://localhost.com/?paramA=hello&?paramB=world

参考:parseQueryString Docs

尽管您的问题似乎是如何解析 来自单个传递参数的字符串标记,不是吗?无论如何决定包括这个答案,因为这是 google 关于如何通过 url 将多个参数传递给 shiny app 的第一个结果,我相信其他人会发现有用。