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

Is it possible to update modal spinner text ? #19

Closed
mgarnault opened this issue Jan 18, 2022 · 4 comments
Closed

Is it possible to update modal spinner text ? #19

mgarnault opened this issue Jan 18, 2022 · 4 comments

Comments

@mgarnault
Copy link

Hi,

I am wondering if it is possible to update show_modal_spinner() displayed text without using remove_modal_spinner() and then re-define a new show_modal_spinner() (with a different text within) ?
Even if the combination of remove_modal_spinner() and show_modal_spinner() works, it is not very fluid for the user. Indeed, we can see the quick on and off of the spinner box (in addition, it creates some "light flashes" as the spinner box background is sucessively shaded and unshaded).

Here is what I am currently using :

      show_modal_spinner(spin = "orbit", text = "First part of computation", color = "#08298A")
      Sys.sleep(1) # some computation
      remove_modal_spinner()
      show_modal_spinner(spin = "orbit", text = "Second part of computation", color = "#08298A")
      Sys.sleep(1) # some other computation
      remove_modal_spinner()

Here is what I'm looking for :

      show_modal_spinner(spin = "orbit", text = "First part of computation", color = "#08298A")
      Sys.sleep(1) # some computation
      updateText_modal_spinner("Second part of computation")
      Sys.sleep(1) # some other computation
      remove_modal_spinner()

Thanks !

@mgarnault
Copy link
Author

Mea culpa,

I had not tried to put directly a show_modal_spinner() after a show_modal_spinner(), which gives the result I was looking for...

The solution :

      show_modal_spinner(spin = "orbit", text = "First part of computation", color = "#08298A")
      Sys.sleep(1) # some computation
      show_modal_spinner(spin = "orbit", text = "Second part of computation", color = "#08298A")
      Sys.sleep(1) # some other computation
      remove_modal_spinner()

This non-problem is therefore closed.

@mgarnault mgarnault reopened this Jan 26, 2022
@mgarnault
Copy link
Author

After some trials I have discovered a bug caused by calling successively show_modal_spinner() without using remove_modal_spinner() inbetween.
Indeed, when the page content requires an Y-scrollbar due to overflowing vertical content, the use of successive show_modal_spinner() leads to an horizontal shrinkage of the page content. In particular, at each computation phase (that displays the spinners), the page content shrinks by one Y-scrollbar width.

Here is a reproducible example using shinydasboard :

library(shiny)
library(shinydashboard)
library(shinybusy)

ui = dashboardPage(
  dashboardHeader(),
  dashboardSidebar(),
  dashboardBody(actionButton("go", "Run computation"),
                box(height = 5000,
                    title = "A very high box which implies the presence of a Y-scrollbar"))
)

server = function(input, output, session){
  observeEvent(input$go,{
    show_modal_spinner(text = "Computation part1")
    Sys.sleep(.25)
    # remove_modal_spinner()
    
    show_modal_spinner(text = "Computation part2")
    Sys.sleep(.25)
    # remove_modal_spinner()
    
    show_modal_spinner(text = "Computation part3")
    Sys.sleep(.25)
    # remove_modal_spinner()
    
    show_modal_spinner(text = "Computation part4")
    Sys.sleep(.25)
    remove_modal_spinner()
  })
}

shinyApp(ui, server)

You will see (I hope) the horizontal shrinkage with this version of code. If you uncomment the "remove_modal_spinner()" functions, you will see that the shrinkage vanishes !
Therefore, I am still looking for a working and stable solution to update spinner texts without using remove_modal_spinner(), as it creates a non-fluid experience for the user as I described in my original post (quick on and off of the spinner box which leads to kind of "light flashes" as the background is sucessively shaded and unshaded).
Can you help me on that ?

Thank you in advance !

@pvictor
Copy link
Member

pvictor commented Jan 26, 2022

Indeed that's ennuyeux.
If you re-install from GitHub, there's a new function update_modal_spinner(), so you can do in your server:

observeEvent(input$sleep1, {
  show_modal_spinner(spin = "orbit", text = "First part of computation", color = "#08298A")
  Sys.sleep(2) # some computation
  update_modal_spinner("Second part of computation")
  Sys.sleep(3) # some other computation
  remove_modal_spinner()
})

Victor

@mgarnault
Copy link
Author

mgarnault commented Jan 26, 2022

Great, this works flawlessly !
Thanks a lot for your responsiveness.

Maxime

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