在闪亮的应用程序中创建一个带有国旗的 multi.sj 闪亮的小部件

Create a multi.sj shiny widget with country flags in shiny app

我正在尝试创建一个像这样 multi.js 闪亮的小部件 here。但是我想念 flags 对象。有人知道我在哪里可以找到并加载它吗?

library(shiny)
library(shinyWidgets)
 countries<-c("Belgium","Greece","Brazil")

ui <- fluidPage(
  multiInput(
    inputId = "Id010",
    label = "Countries :", 
    choices = NULL,
    choiceNames = lapply(seq_along(countries), 
                         function(i) tagList(tags$img(src = flags[i],
                                                      width = 20, 
                                                      height = 15), countries[i])),
    choiceValues = countries
  )
)

server <- function(input, output) {
  
  
  
}

shinyApp(ui, server)

根据 chrome 的开发工具,shinyWidgets 画廊中的图像似乎是从如下网址提取的:https://cdn.rawgit.com/lipis/flag-icon-css/master/flags/4x3/de.svg.

如果您想将其包含在输入小部件中,您需要定义一个包含相应 url 的字符向量

countries <- c('de', 'at', 'br')

img_urls <- paste0(
  'https://cdn.rawgit.com/lipis/flag-icon-css/master/flags/4x3/',
  countries, '.svg'
)

input_widget <- multiInput(
  inputId = "Id010",
  label = "Countries :", 
  choices = NULL,
  choiceNames = lapply(
    seq_along(countries), 
    function(i) {
      tagList(
        tags$img(src = img_urls[i], width = 20, height = 15), 
        countries[i]
      )
    }
  ),
  choiceValues = countries
)

然后您可以将输入小部件放在您身体的任何位置UI

shinyApp(fluidPage(input_widget), function(...) {})