plotly + renderUI + withLoader

Good morning, everyone,

So here's another little question for the community :sweat_smile:

In my application I want to select a number of graphics. Depending on the length of the returned list, I use a renderUI to put them in a predefined configuration. In addition, in order not to have a white interface, I use withLoader.

mylist <- reactive({input$mylist})
  
observe({
    mylist <- mylist()
    output$plot1 <- renderPlotly(toAnalysis$plots[[paste0("plot_",poc[1])]])
    output$plot2 <- renderPlotly(toAnalysis$plots[[paste0("plot_",poc[2])]])
    output$plot3 <- renderPlotly(toAnalysis$plots[[paste0("plot_",poc[3])]])
    output$plot4 <- renderPlotly(toAnalysis$plots[[paste0("plot_",poc[4])]])
  })

output$plots_dataset <- renderUI({
    mylist <- mylist()
    
    if(is.null(mylist)){
      tagList(
        tags$h1("No data was selected")
      )
    }
    
    switch(length(mylist),
           "1" = {
             tagList(
               withLoader(
                 plotlyOutput("plot1"),
                 type = "html",
                 loader = "dnaspin"
               )
             )
           },
           "2" = {
             tagList(
               withLoader(
                 plotlyOutput("plot1"),
                 type = "html",
                 loader = "dnaspin"
               ),
               br(),
               withLoader(
                 plotlyOutput("plot2"),
                 type = "html",
                 loader = "dnaspin"
               )
             )
           },
           "3" = {
             tagList(
               fluidRow(
                 column(6,
                        withLoader(
                          plotlyOutput("plot1"),
                          type = "html",
                          loader = "dnaspin"
                        )
                 ),
                 
                 column(6,
                        withLoader(
                          plotlyOutput("plot2"),
                          type = "html",
                          loader = "dnaspin"
                        )
                 )
               ),
               br(),
               fluidRow(
                 column(6,
                        offset = 3,
                        withLoader(
                          plotlyOutput("plot3"),
                          type = "html",
                          loader = "dnaspin"
                        )
                 )
               )
             )
           },
           "4" = {
             tagList(
               fluidRow(
                 column(6,
                        withLoader(
                          plotlyOutput("plot1"),
                          type = "html",
                          loader = "dnaspin"
                        )
                 ),
                 br(),
                 column(6,
                        withLoader(
                          plotlyOutput("plot2"),
                          type = "html",
                          loader = "dnaspin"
                        )
                 )
               ),
               fluidRow(
                 column(6,
                        withLoader(
                          plotlyOutput("plot3"),
                          type = "html",
                          loader = "dnaspin"
                        )
                 ),
                 br(),
                 column(6,
                        withLoader(
                          plotlyOutput("plot4"),
                          type = "html",
                          loader = "dnaspin"
                        )
                 )
               )
             )
           }
    )
})

But as you can see, the loader of the plot1 continues to be present... This blocks the interaction of the graph at the same time. Because clicks are made 1 to 1 so in the switch it will load the configuration 1 then the 2

How can I solve the problem?
I've tried many things but nothing works.
I was thinking about destroying the graphics and then reloading them, but I couldn't find a solution

Might be a bug in withLoader(), what package is that from?

It's from shinycustomloader. But I solved the problem.
It must be to do

withLoader(
      renderPlotly({myplot}),
      type = "html",
      loader = "loader1")

But if someone can explain me, I take. :smile: