Update the "imageOutput" widget

Intent: I have 7 images, which can be switched through

  output$image <- renderImage({
    if (is.null(input$chooseImg))
      return(NULL)
    
    if (input$chooseImg == "pump1 vs all")
      return(list(src = "images/roc_1vsall.png", width = "80%", height = "520"))
    
    else if (input$chooseImg == "pump2 vs all")
      return(list(src = "images/roc_2vsall.png", width = "80%", height = "520"))
    
    else if (input$chooseImg == "pump3 vs all")
      return(list(src = "images/roc_3vsall.png", width = "80%", height = "520"))
    
    else if (input$chooseImg == "pump4 vs all")
      return(list(src = "images/roc_4vsall.png", width = "80%", height = "520"))
    
    else if (input$chooseImg == "pump5 vs all")
      return(list(src = "images/roc_5vsall.png", width = "80%", height = "520"))
    
    else if (input$chooseImg == "pump6 vs all")
      return(list(src = "images/roc_6vsall.png", width = "80%", height = "520"))
    
    else if (input$chooseImg == "pump7 vs all")
      return(list(src = "images/roc_7vsall.png", width = "80%", height = "520"))
    
  }, deleteFile = FALSE)

I wanna switch the image to a special one, when user click on a button. And this special image is not an option of the selectInput box. And user can reset to any default images(the 7 images) by clicking the selectInput box.

Problem: While my code works well on displaying the special image, when I try to reset to any of the 7 images, the image simply does not change. My later code after those in the "intent" part:

  observeEvent(input$submit_par, {
    user_parameters <- reactiveValues()
    user_parameters$eps <- input$epsilon_in
    user_parameters$minPts <- input$minPts_in
    output$image <- isolate(renderImage({return(list(src = "images/surprise.jpg"))}, deleteFile = FALSE))
  })

Thank you in advance for any idea! :sweat_smile:

your observeEven on submit_par overwrites your previous output$image renderImage so chooseImg is no longer registered as an input on it after submit_par is pressed.

maybe choose the same observeEvent wrapping on chooseImg like

observeEvent(input$chooseImg,{
output$image <- renderImage({
    req(input$chooseImg)
    
    if (input$chooseImg == "pump1 vs all")
      return(list(src = "images/roc_1vsall.png", width = "80%", height = "520"))
    
etc

so that when chooseImg slider is moved the output$image is redefined away from the one that had been set by the submit_par trigger.

1 Like

Thank you very much, Nirgrahamuk. Your reply perfectly solve my problem. :+1:

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