Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

allow additional text in progressSweetAlert and updateProgressBar #671

Closed
agilly opened this issue Mar 5, 2024 · 3 comments
Closed

allow additional text in progressSweetAlert and updateProgressBar #671

agilly opened this issue Mar 5, 2024 · 3 comments

Comments

@agilly
Copy link

agilly commented Mar 5, 2024

Hi!

This is more of a feature request than an issue. Currently, we are able to create sweetAlerts of various types with a title and text:

sendSweetAlert(
            session = session,
            title = "Error",
            text = "Please select at least one item",
            type="error"
        )

We are also able to use a progress bar modal in a sweet alert:

##UI
 useSweetAlert()
####

##server
            progressSweetAlert(
                session=session,
                id="myProgress",
                title="Doing stuff",
                display_pct=T,
                value=0, status="info", striped=T
            )
for(i in 1:10){
                perform_long_computation()
                updateProgressBar(session=session, id="myProgress", title="Calculating...",value=i*10)
}

In the documentation, it says that progressSweetAlert's remaining arguments are passed to sendSweetAlert:
... Arguments passed to sendSweetAlert()

However that doesn't extend to the text argument, because if I use it, I get:

Warning: Error in sendSweetAlert: formal argument "text" matched by multiple actual arguments

My guess is that text is overloaded to contain the progress bar. Is there a way, however, to make progressSweetAlert and updateProgressBar accept some additional text? It would help building more dynamic and informative progress bars.

Even if this suggestion is rejected, any workaround is also appreciated!

@pvictor
Copy link
Member

pvictor commented Mar 6, 2024

Hello,
Yes you're right, text is used to put the progress bar, there's no easy way to put some text at the moment, beside of title.
But progressSweetAlert() is just a wrapper around sendSweetAlert() and progressBar(), so you can easily make a version that suit your needs, for example something like :

library(shiny)
library(shinyWidgets)

ui <- fluidPage(
  actionButton("show", "Show progress")
)

server <- function(input, output, session) {
  observeEvent(input$show, {
    sendSweetAlert(
      session = session,
      title = NULL,
      btn_labels = NA,
      text = tags$div(
        progressBar(
          id = "myprogress",
          title = "Work in progress",
          display_pct = TRUE, 
          value = 0
        ),
        tags$div(
          id = "mytext", 
          tags$p("Here you can put some text")
        )
      ),
      closeOnClickOutside = FALSE,
      backdrop = TRUE
    )
    for (i in seq_len(50)) {
      Sys.sleep(0.1)
      updateProgressBar(
        session = session,
        id = "myprogress",
        title = "Work in progress",
        value = i*2
      )
      if (i == 25) {
        removeUI("#mytext p", immediate = TRUE)
        insertUI(
          selector = "#mytext", 
          ui = tags$p("This text has been updated"),
          immediate = TRUE
        )
      }
    }
    closeSweetAlert(session = session)
  })
}

shinyApp(ui, server)

There's also some alternative for a progress modal here : https://dreamrs.github.io/shinybusy/reference/modal-progress.html if you're interested.

Victor

@agilly
Copy link
Author

agilly commented Mar 8, 2024

Thank you very much @pvictor , this is super useful. I tried the shinybusy solution and it works great! Will update my current progress bars with the wrapper you suggested soon.

@agilly
Copy link
Author

agilly commented Mar 8, 2024

Also tested your solution for the progress bar, it works well. The style of "#mytext" is a bit heavy but I assume p() can be replaced or styled to a lighter/smaller font.

@pvictor pvictor closed this as completed Mar 27, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants