R shiny - insertUI()'s “immediate” argument does not work with images

风格不统一 提交于 2021-02-11 14:06:46

问题


I am trying to update divs while in a loop, some of which contain images. Using removeUI(..., immediate = TRUE) I can remove them and then replace them by new divs, with insertUI(..., immediate = TRUE). Although the texts appear in real time, the images do not load until we are out of the loop (see example below, you don't even have to load an image, a question mark will appear after the loop ends).

In my browser I can see the img tags are created in HTML, but still no images appear live.

Here is a reproducible example:

ui <- fluidPage(
  actionButton("add","")
)
server <- function(input, output, session) {
  for(i in 1:3){
    Sys.sleep(1.5)
    insertUI(
      selector = "#add",
      where = "afterEnd",
      ui = div(style = paste0("width: 75px; height: 75px; background-color: white;"), h5("Text appears live", align = "center"), 
               div(h6("Text inside a div appears live")),
               div(id = "img", img(src = "image.jpg", alt = "Images do not appear live")
               )
      ),
      immediate = TRUE
    )
  }
}
shinyApp(ui, server)

Is this normal behavior for shiny? If so is their a way to bypass it and to see the images appear directly? Another way to do it?

来源:https://stackoverflow.com/questions/56908652/r-shiny-insertuis-immediate-argument-does-not-work-with-images

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!