JohnCoene / waiter

🕰️ Loading screens for Shiny
https://waiter.john-coene.com/
Other
499 stars 25 forks source link

Update Messages Alongside Hostess Progress #149

Open jmestret opened 7 months ago

jmestret commented 7 months ago

Hi! First of all, thank you for developing such a useful package. I have a problem with using Hostess and dynamic text. I have successfully implemented dynamic messages with the spinner. However, my current approach feels somewhat inelegant, and I'm wondering if there is a cleaner alternative. The problem arises when trying to switch from the spinner to a Hostess loader while simultaneously updating messages. Is it possible to update messages while updating the Hostess progress?

I am attaching below the method I used with the spinner.

Thank you very much!

library(shiny)
library(waiter)

ui <- fluidPage(
    useWaiter(),
    actionButton("show", "Show loading with updates")
)

server <- function(input, output, session){
    # create the waiter
    waiting_screen <- tagList(
        spin_flower(),
        h4("Cool stuff loading...")
    )
    w <- Waiter$new(html = waiting_screen)

    msgs <- c("Loading data", "Running model", "Drawing plots")

    observeEvent(input$show, {
        w$show()

        Sys.sleep(2)

        for(i in 1:3){
            w$update(html = tagList(
                spin_flower(),
                h4(msgs[i])
            ))
            Sys.sleep(2)
        }

        w$hide()
    })
}

shinyApp(ui, server)
JohnCoene commented 7 months ago

Ah, I did not think of that combination. I don't really have a solution right now: I need to think of something.