gpt4 book ai didi

r - 将国家标志添加到选择器输入的 Shiny 小部件。

转载 作者:行者123 更新时间:2023-12-04 11:40:30 24 4
gpt4 key购买 nike

有一个示例如何将国家标志添加到 checkBoxGroupInput这里

https://gist.github.com/bborgesr/f2c865556af3b92e6991e1a34ced2a4a

我正在尝试使用 pickerinput 稍微调整代码以达到相同的结果来自 Shiny 的小部件。但是,在我的结果中,我看不到任何图像。

  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)

最佳答案

嗨,您不想将选项添加为 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)

希望这可以帮助!

关于r - 将国家标志添加到选择器输入的 Shiny 小部件。,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47741321/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com