Skip to content

Instantly share code, notes, and snippets.

@PaulC91
Last active February 24, 2021 04:07
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save PaulC91/ae82c74b2eef9881934d2616ec9b019c to your computer and use it in GitHub Desktop.
Save PaulC91/ae82c74b2eef9881934d2616ec9b019c to your computer and use it in GitHub Desktop.
shinyWidgets::pickerInput with images
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