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

Spinner does not appear in Shiny application #48

Open
edwardlavender opened this issue Oct 24, 2022 · 6 comments
Open

Spinner does not appear in Shiny application #48

edwardlavender opened this issue Oct 24, 2022 · 6 comments
Labels
upstream Bug in upstream repo

Comments

@edwardlavender
Copy link

I have wrapped the example for ?addSpinner into an R Shiny application., but the spinner does not appear.

Here is a reproducible example based on the example given for ?addSpinner. I expected a spinner to appear during the 'sleep' phase, but no spinner appears.

library(shiny)
library(leaflet)
library(leaflet.extras2)
library(magrittr)

ui <- fluidPage(
  leafletOutput("leaf")
)

sleep <- function(map){
  Sys.sleep(5)
  map
}

server <- function(input, output){
  output$leaf <- 
    renderLeaflet({
      leaflet(data = quakes) %>%
        addTiles()  %>%
        addSpinner() %>%
        startSpinner(options = list("lines" = 7, "length" = 20)) %>%
        sleep() %>%
        addMarkers(~long, ~lat, popup = ~as.character(mag), label = ~as.character(mag)) %>%
        stopSpinner()
    })
}

shinyApp(ui, server)
@trafficonese
Copy link
Owner

I'm pretty sure this is a bug in the upstream repo. There is not much I can do with this plugin. Its either start or stop the spinner.
I think it could be related to this issue makinacorpus/Leaflet.Spin#12

@trafficonese trafficonese added the upstream Bug in upstream repo label Oct 25, 2022
@trafficonese
Copy link
Owner

You could maybe do something like that:

library(shiny)
library(leaflet)
library(leaflet.extras2)
library(shinyjs)

ui <- fluidPage(
  useShinyjs(),
  actionButton("go", "Go"),
  leafletOutput("leaf")
)

server <- function(input, output){
  mapready <- reactiveVal(NULL)
  output$leaf <- renderLeaflet({
    m <- leaflet() %>%
        addTiles() %>% 
        leaflet.extras2::addSpinner() 
    shinyjs::delay(500, mapready(TRUE))
    m
  })
  observe({
    req(mapready())
    leafletProxy("leaf") %>% 
      startSpinner(list("lines" = 7, "length" = 40,
                        "width" = 20, "radius" = 10)) %>%
      clearGroup("quk") %>% 
      addMarkers(data = quakes, ~long, ~lat, group="quk",
                 popup = ~as.character(mag), label = ~as.character(mag)) %>%
      leaflet.extras2::stopSpinner()
  })
}

shinyApp(ui, server)

@edwardlavender
Copy link
Author

That's great - thanks a lot!

@radbasa
Copy link

radbasa commented May 6, 2024

@trafficonese I'll take a look at this and see if we can make it work like it did when this was merged.

@trafficonese
Copy link
Owner

@radbasa I'm not sure what you mean. :) Did you maybe write in a wrong issue?

@radbasa
Copy link

radbasa commented May 16, 2024

@radbasa I'm not sure what you mean. :) Did you maybe write in a wrong issue?

I'll take a look at the spinner again, and see if the "bug" mentioned above can be fixed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
upstream Bug in upstream repo
Projects
None yet
Development

No branches or pull requests

3 participants