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

ggplot's popup bug #12

Closed
lvallata opened this issue Mar 19, 2020 · 1 comment
Closed

ggplot's popup bug #12

lvallata opened this issue Mar 19, 2020 · 1 comment

Comments

@lvallata
Copy link

Here is the link to stackoverflow post (reproducible example inside).
https://stackoverflow.com/questions/60741317/shiny-leafpopaddpopupgraphs-bug-looking-for-a-walkaround

Best,
Lukic

@tim-salabim
Copy link
Member

Sorry for the long silence.

Seems like you need to update the group argument when input$potatoes changes:
This works for me:

library(shiny)
library(leaflet)
library(leafpop)
library(ggplot2)

ui = fluidPage(
  sliderInput(inputId = "potatoes",
              label = "Potatoes:",
              min = 1,
              max = 10,
              value = 2,
              step = 1,
              animate = F,
              width = '100%'),
  leafletOutput('my_map', height = 700)
)

server = function(input, output, session) {
  
  output$my_map <- renderLeaflet({
    
    my_map <- function(my.var = character()){
      
      my.plot <- ggplot(mtcars, aes(cyl, mpg)) + geom_line()
      
      m <- leaflet() %>%
        addTiles(urlTemplate = 'https://{s}.tile.opentopomap.org/{z}/{x}/{y}.png') %>%
        setView(lng = 10,
                lat = 49,
                zoom = 4) %>%
        addCircleMarkers(lng = c(10, 10),
                         lat = c(49, 50),
                         group = paste0('A', input$potatoes),
                         label = my.var
        ) %>%
        addPopupGraphs(list(my.plot,my.plot),
                       group = paste0('A', input$potatoes),
                       width = 500, height = 300)
      
      return(m)
    }
    
    my_map(input$potatoes)
  })
}

shinyApp(ui, server)

Screenshot from 2020-07-01 19-23-59

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