I would like to figure out how to use renderImage in Shiny with online images (URLs) and make the image clickable so that I can put the registerEvent () function on it. I can do both, but not together. My approach to displaying a URL does not work with a click, and the local version of the image that allows me to click does not display URL images.
Here are two half working versions: I found inspiration here for
Clickable
library(shiny)
ui <- fluidPage(
imageOutput("image1", click = "MyImage")
)
server <- function(input, output, session) {
setwd(Set the directory of the image in here)
output$image1 <- renderImage({
list(
src = "YOUR_IMAGE.png",
contentType = "image/png",
width = 90,
height = 78,
alt = "This is alternate text"
)}, deleteFile = FALSE)
observeEvent(input$MyImage, { print("Hey there")})
}
shinyApp(ui, server)
if I put the url (and delete deleteFile = FALSE), it shows an empty square. still clickable though.
Url using renderUI()
library(shiny)
ui <- fluidPage(
uiOutput("image1", click = "MyImage")
)
server <- function(input, output, session) {
setwd(AppDir)
output$image1<- renderUI({
imgurl2 <- "https://www.rstudio.com/wp-content/uploads/2014/07/RStudio-Logo-Blue-Gradient.png"
tags$img(src=imgurl2, width = 200, height = 100)
})
observeEvent(input$MyImage, { print("Hey there")})
}
shinyApp(ui, server)
shows the image, but the image is no longer viewable.
renderUI() uiOuput() renderImage() imageOutput() 2, " ".
htmlOuput renderText
, SO, , .
library(shiny)
ui <- fluidPage(
htmlOutput("image1", click = "MyImage")
)
server <- function(input, output, session) {
setwd(AppDir)
imgurl2 <- "https://www.rstudio.com/wp-content/uploads/2014/07/RStudio-Logo-Blue-Gradient.png"
output$image1<- renderText({c('<img src="',imgurl2,'">')})
observeEvent(input$MyImage, { print("Hey there")})
}
shinyApp(ui, server)
, Shiny App. , URL- . , - , click = imageOutput.