Link/click here- should display below image.

Hi

Can anyone help me on below...
how can we add both image and hyperlink in 'if/else' condition.

Link should display below image.

output$mob <- renderImage({

if(input$mobiles == "Apple"){

  return(list(

######here i want to add hyperlink
src = "www/iphone.jpg",
filetype = "image/jpg"
))}

  else{
    return(list(
      src = "www/shop.jpg",
      filetype = "image/jpg"

    ))
  }

Hi,
Adaptation on my previous comment

library(shiny)
shiny_imgs <- list.files(path = system.file(package = "shiny"), pattern = ".png", recursive = TRUE, full.names = TRUE)
ui <- fluidPage(selectInput(inputId = "img_list", label = "logo", choices = basename(shiny_imgs),
                            selected = basename(shiny_imgs)[1], multiple = FALSE),
                div(id = "img_placeholder"))
server <- function(input, output, session) {
  observeEvent(input$img_list, {
    path_to_img = shiny_imgs[basename(shiny_imgs) == input$img_list]
    url = "https://forum.posit.co/t/how-to-insert-an-clickable-image-in-shiny-r/111026?"
    removeUI(selector = "#img_placeholder>div", multiple = TRUE, immediate = TRUE)
    insertUI(selector = "#img_placeholder", where = "afterBegin", multiple = FALSE, immediate = TRUE,
             ui = tags$div(style = "width:200px;",
               tags$a(href=url,
                         tags$img(height = 200, width = 200, 
                                  src = session$fileUrl(name = "logo", contentType = "data:image/png",
                                                        file = path_to_img)),
                         url))
    )
  })
}
shinyApp(ui, server)

This topic was automatically closed 54 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.