Last active
February 24, 2021 04:07
-
-
Save PaulC91/ae82c74b2eef9881934d2616ec9b019c to your computer and use it in GitHub Desktop.
shinyWidgets::pickerInput with images
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(shiny) | |
library(magrittr) | |
# images for picker input stored in www/img/ from the root app directory | |
imgs <- fs::dir_ls("www/img") %>% stringr::str_remove("www/") # remove www/ from filepath | |
img_name <- fs::path_file(imgs) %>% fs::path_ext_remove() # get image name without extension | |
select_choice_img <- function(img, text) { | |
shiny::HTML(paste( | |
tags$img(src=img, width=30, height=22), | |
text | |
)) | |
} | |
ui <- fluidPage( | |
shinyWidgets::pickerInput( | |
inputId = "select", | |
label = "Select", | |
choices = img_name, | |
choicesOpt = list(content = purrr::map2(imgs, img_name, select_choice_img)) | |
) | |
) | |
server <- function(input, output, session) { | |
} | |
shinyApp(ui, server) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment