2017-12-10 11 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 문자열로 tagList 등의 옵션을 추가하고 싶지 않아!

+0

바튼 도움이 되셨습니다. 감사합니다. 그래도 질문을 던지면 국가 이름을 지우고 깃발 만 남기고 options = list ('live-search' = T)를 포함하고 "Australia"를 검색하고 플래그를 표시 할 수 있습니까? – MLEN