0

I want to put a local image instead of an HTML image inside modalDialog.

observeEvent(input$execute, {
     showModal(modalDialog(
     title = "Title",
     HTML('<img src="http://www.google.nl/images/branding/googlelogo/2x/googlelogo_color_272x92dp.png">'),
     easyClose = TRUE,
     footer = NULL
   ))
})

actionButton(inputId = "execute", label = "Click")

Something like:

observeEvent(input$execute, {
  showModal(modalDialog(
    title = "Title",
    "~/Documents/folder/images/image1.png",
    easyClose = TRUE,
    footer = NULL
  ))
})
neves
  • 796
  • 2
  • 10
  • 36

1 Answers1

1

You should put the image in the www folder, located in the same directory as the app file :

library(shiny)

# Define UI 
ui <- fluidPage(

    # Application title
    titlePanel("Modal with image"),
        # Execute modal button
        mainPanel(
            actionButton("execute", "Click Me")
        )
)

# Define server logic 
server <- function(input, output) {

    observeEvent(input$execute, {
        showModal(modalDialog(
            title = "Title",
            HTML('<img src="googlelogo_color_272x92dp.png" />'),
            easyClose = TRUE,
            footer = NULL
        ))
    })
}

# Run the application 
shinyApp(ui = ui, server = server))

enter image description here

Waldi
  • 39,242
  • 6
  • 30
  • 78