这里有一个如何将国家标志添加到checkBoxGroupInput的示例
https://gist.github.com/bborgesr/f2c865556af3b92e6991e1a34ced2a4a
我正在尝试稍微调整代码,以使用shinywidgets中的pickerinput实现相同的结果。然而,在我的结果中,我没有看到任何图像。
library(shiny)
library(shinyWidgets)
countries <- c("Australia", "United Kingdom", "United States")
flags <- c(
"https://cdn.rawgit.com/lipis/flag-icon-css/master/flags/4x3/au.svg",
"https://cdn.rawgit.com/lipis/flag-icon-css/master/flags/4x3/gb.svg",
"https://cdn.rawgit.com/lipis/flag-icon-css/master/flags/4x3/us.svg"
)
ui <- fluidPage(
pickerInput("countries", "countries", multiple = T,
choices = countries,
choicesOpt = list(content =
mapply(countries, flags, FUN = function(country, flagUrl) {
tagList(
tags$img(src=flagUrl, width=20, height=15),
country
)
}, SIMPLIFY = FALSE, USE.NAMES = FALSE)
))
,
textOutput("txt")
)
server <- function(input, output, session) {
output$txt <- renderText({
paste("You chose", paste(input$countries, collapse = ", "))
})
}
shinyApp(ui, server)发布于 2017-12-13 22:59:34
您好,您不想添加选项作为tagList,而是像下面这样的HTML字符串
library(shiny)
library(shinyWidgets)
countries <- c("Australia", "United Kingdom", "United States")
flags <- c(
"https://cdn.rawgit.com/lipis/flag-icon-css/master/flags/4x3/au.svg",
"https://cdn.rawgit.com/lipis/flag-icon-css/master/flags/4x3/gb.svg",
"https://cdn.rawgit.com/lipis/flag-icon-css/master/flags/4x3/us.svg"
)
ui <- fluidPage(
pickerInput("countries", "countries", multiple = T,
choices = countries,
choicesOpt = list(content =
mapply(countries, flags, FUN = function(country, flagUrl) {
HTML(paste(
tags$img(src=flagUrl, width=20, height=15),
country
))
}, SIMPLIFY = FALSE, USE.NAMES = FALSE)
))
,
textOutput("txt")
)
server <- function(input, output, session) {
output$txt <- renderText({
paste("You chose", paste(input$countries, collapse = ", "))
})
}
shinyApp(ui, server)希望这能有所帮助!
https://stackoverflow.com/questions/47741321
复制相似问题