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

render mapboxer on shiny #79

Open
Jorge-hercas opened this issue Jul 17, 2021 · 3 comments
Open

render mapboxer on shiny #79

Jorge-hercas opened this issue Jul 17, 2021 · 3 comments

Comments

@Jorge-hercas
Copy link

Hello everyone, i have a problem to render a filtered mapboxer on shiny. I get the error Problem withmutate()columncolor. e[34mℹe[39m color = pal(pop_est). e[31mxe[39m unused argument (pop_est) and i don't now why.

Any ideas or suggestions?
Thanks for reading me
The code is the following:

data("World")

ui <- fluidPage(
  
  selectInput("var","escoge un continente",
              choices = list("Asia" = "Asia",
                             "Africa" = "Africa",
                             "Europa" = "Europe",
                             "America" = "North America")       
  ),
  mapboxerOutput("map")
  
)

server <- function(input, output){
  
  dato <- reactive({
    
    World |> 
      filter(continent == input$var)
  
  })
  
  pal <- reactive({
    scales::col_quantile("Greys",  dato()$pop_est)
  })
  
  bbox <- reactive({
    unname(sf::st_bbox(dato() ))
  })
  
  output$map <- renderMapboxer({
    
    dato() %>%
      dplyr::mutate(color = pal(pop_est)) %>%
      as_mapbox_source() %>%
      mapboxer(bounds = bbox(), pitch = 25, zoom = 10) %>%
      add_navigation_control() %>%
      add_fill_layer(
        fill_color = c("get", "color"),
        fill_opacity = 0.5,
        fill_outline_color = "white",
        popup = "Población estimada: {{pop_est}}"
      )
    
  })
  
  
  
}



shinyApp(ui, server)
@crazycapivara
Copy link
Owner

Hi @Jorge-hercas If you want to update / filter an already rendered map it is recommended to use use mapboxer_proxy and update_mapboxer in conjunction with the filter parameter. To update the extend you can use fit_bounds.

@Jorge-hercas
Copy link
Author

Thanks a lot for the answer
I tried it but I get an error again :(

The code is the following:

data("World")
ui <- fluidPage(
  selectInput("var","escoge un continente",
              choices = list("Asia" = "Asia",
                             "Africa" = "Africa",
                             "Europa" = "Europe",
                             "America" = "North America")
              
              
  ),
  mapboxerOutput("map")
  
) 

server <- function(input, output, session) {
  
  dato <- reactive({
    
    World |> 
      filter(continent == input$var)
    
  })
  
  pal <- reactive({
    scales::col_quantile("Greys",  dato()$pop_est)
  })
  
  bbox <- reactive({
    unname(sf::st_bbox(dato() ))
  })
  
  output$map <- mapboxer::renderMapboxer({
    mapboxer(bounds = bbox(), pitch = 25, zoom = 10)
  })
  
  observeEvent(input$var, {    
    dplyr::mutate(color = pal(pop_est ))  |> 
      as_mapbox_source(dato ) |> 
      add_navigation_control() |> 
      add_fill_layer(
        fill_color = c("get", "color"),
        fill_opacity = 0.5,
        fill_outline_color = "white",
        popup = "Población estimada: {{pop_est}}"
      )
  })    
  
}

shinyApp(ui, server)

@crazycapivara
Copy link
Owner

Please see this example

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