carlganz / rintrojs

Wrapper for the Intro.js library
http://rintrojs.carlganz.com/
GNU Affero General Public License v3.0
133 stars 11 forks source link

UI elements destroyed and recreated, singleton #54

Closed gregleleu closed 2 years ago

gregleleu commented 2 years ago

My app is behind a login module: the UI is generated only when the user is logged in using renderUI. First time around everything is fine. However if a user logs out :

From reading the code, I think it's due to the shiny::singleton call, as the documentation says: Only the first appearance of the content (in document order) will be used I'm pretty sure it stops the UI elements wrapped with introBox from being created again

For the moment I'm fixing it but doing

div(
  plotOutput("plot"),
  `data-step` = 1,
  `data-intro` = "this is a plot"
)

instead of introBox()

Why the call to singleton?

carlganz commented 2 years ago

I honestly don't remember why I used singleton and my Shiny skills are very rusty. I'd be open to a PR that removes it.

For sanity check could you please share a minimal reproducible example?

gregleleu commented 2 years ago

Reprex below

library(shiny)
library(rintrojs)

# Define UI for application that draws a histogram
ui <- fluidPage(

  # Application title
  titlePanel("Reprex"),
  fluidRow(
    column(12,
           checkboxInput("check_show", "Show UI?", value = FALSE)
    )
  ),
  fluidRow(
    column(12,
           uiOutput("ui_out")
    )
  )
)

# Define server logic required to draw a histogram
server <- function(input, output) {

  output$ui_out <- renderUI({
    if (input$check_show) {
      tagList(
        p("Always rendered (not wrapped in introBox)"),
        introBox(
          p("Rendered only the first time"),
          data.step = 1,
          data.intro = "Hello"
        ),
        div(
          p("Rendered because of a workaround"),
          `data-step` = 1,
          `data-intro` = "Hello"
        )
      )

    } else {
      p("click on checkbox to show")
    }

  })
}

# Run the application 
shinyApp(ui = ui, server = server)
gregleleu commented 2 years ago

Removing the shiny::singleton wrapper in introBox works on my example. Lookin at the git history you had the singleton wrapper from day 1, not sure for what purpose

zagrebmukerjee commented 2 years ago

Had the exact same problem. Same solution works.