3

I am trying to create a map in the mainPanel and two buttons in the sidebarPanel. I have two maps and I want them to appear in the mainPanel after pressing a specific button.

These maps work outside shiny.

     ui <- fluidPage(  
     sidebarLayout(
     sidebarPanel(
       actionButton("do2", "unemployed women"),
     actionButton("do3", "unemployed men")
     ),
       mainPanel(
     leafletOutput("mymap2"),
     leafletOutput("mymap3")
     ) 
     )
     )
     # Define the server logic
     server <- function(input, output) {
     observeEvent(input$do2, {
     output$mymap2 <- renderLeaflet({
     tm <- tm_shape(woj_shp) +
     tm_fill(col = "unemployed_women", title = "unemployed women", palette = 
     "-GnBu") + 
     tm_borders()+
     tm_layout(inner.margins=c(.15,.13, .05, .05))+
     tm_text("unemployed_women", col="black", palette="Dark2") 
     tmap_leaflet(tm)
     })
     }
     )
     observeEvent(input$do3, {
     output$mymap3 <- renderLeaflet({
     tm2 <- tm_shape(woj_shp) +
     tm_fill(col = "unemployed_men", title = "unemployed men", palette = "- 
     GnBu") + 
     tm_borders()+
     tm_layout(inner.margins=c(.15,.13, .05, .05))+
     tm_text("unemployed_men", col="black", palette="Dark2") 
     tmap_leaflet(tm2)
     })
     }
     )
      }


# Run the application
shinyApp(ui = ui, server = server)

I have the following error:

object 'leaflet_html' not found

lovalery
  • 4,524
  • 3
  • 14
  • 28
Angela
  • 31
  • 2
  • I cannot reproduce your example since I have not the ** woj_shp** file. Are you loading the libraries: `library(tmap) library(leaflet)` – Orlando Sabogal Sep 26 '19 at 15:03

0 Answers0