feddelegrand7 / fabricerin

Create Easily Canvas in Shiny and RMarkdown Documents
https://ihaddadenfodil.com/post/fabricerin-a-tutorial/
Other
54 stars 5 forks source link

Render image inside dynamically created UI? #6

Open dcaud opened 3 years ago

dcaud commented 3 years ago

Would it be be possible to render image inside a UI element that is dynamically created?

Seems like a little javascript would need to be changed.

I'm looking for something like this:

library(fabricerin)

ui <- fluidPage(
  actionButton("render", "Put image on Canvas!"),
  uiOutput("gen.in.server")

)

server <- function(input, output) {

  observeEvent(input$render,{

    output$gen.in.server <- 
      renderUI({

        fabric_image(cid = "cimage",
                     cfill = "lightblue",
                     imgId = "Rimg",
                     imgsrc = "https://upload.wikimedia.org/wikipedia/commons/thumb/1/1b/R_logo.svg/724px-R_logo.svg.png")
      })
  })

}

shinyApp(ui = ui, server = server)
feddelegrand7 commented 3 years ago

hi @dcaud ,

I've tried the code that you've provided and it worked. Try to click twice on the action button and tell me please if it worked.

Best.

dcaud commented 3 years ago

Nice find! Interesting that clicking twice works. It seems like a bug somewhere and I'm not sure how to fix it.

feddelegrand7 commented 3 years ago

Indeed, there is a problem somewhere but can't find it. I won't clause this issue in case someone can fix it.