2017-12-10 6 views
0

は、私がshinywidgetsからpickerinput使用して同じ結果を達成するために、わずかにコードを調整しようとしていますpickerinput shinywidgetsに国旗を追加しています。

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

ここcheckBoxGroupInputに国旗を追加する方法の例があります。しかし、私の結果では私はイメージを見ません。

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) 

答えて

4

こんにちは、あなたはではなく、このことができます。この

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) 

希望のようなHTML文字列としてタグリストなどのオプションを追加する必要はありません!

+0

バートン助けてくれた、ありがとう。ただし、国名を削除してフラグを保持することは可能ですが、options = list( 'live-search' = T)を含めると、たとえば「Australia」を検索してフラグを表示させることはできますか? – MLEN

関連する問題