0

I have multiple raster .tif files that I want to display in the pickerInput, socal_norbaja_coast_gdes, southern_mountains_gdes and sonoran_basin_gdes. There are 11 other ecoregions I want to include but am working with 3 for now. Within my sideBarPanel in my UI, I have this code:

shinyWidgets::pickerInput(inputId = "ecoregion_type_input",
                                                               label = "Select ecoregion:",
                                                               choices = c("socal_norbaja_coast_gdes", "southern_mountains_gdes", "sonoran_basin_gdes"), 
                                                               options = pickerOptions(actionsBox = TRUE),
                                                               selected = c("socal_norbaja_coast_gdes"),
                                                               multiple = TRUE),), # End SideBarPanel

mainPanel(
                        
                        # TMAP UI
                        tmapOutput("map")))),

And my server looks like this:

server <- function(input, output, session) {
   
  
  tm_df <- reactive({
    # proxy <- tmapProxy("map", session)
    
    validate(
      need(length(input$ecoregion_type_input) > 0, "Select more than one ecosystem"))
    
    # tm <- tm_raster() # shape(socal_norbaja_coast_gdes)
    if ("socal_norbaja_coast_gdes" %in% input$ecoregion_type_input) {
      tm_shape(socal_norbaja_coast_gdes) + tm_raster()
    } else if ("southern_mountains_gdes" %in% input$ecoregion_type_input) {
      tm_shape(southern_mountains_gdes) + tm_raster()
    } else if ("sonoran_basin_gdes" %in% input$ecoregion_type_input) {
      tm_shape(sonoran_basin_gdes) + tm_raster()
    }

    # not sure if below is relevant
    tm_df <- tm %>%
      filter(ecoregion_type %in% c(input$ecoregion_type_input))
    tm_df
      
  })
  
  
  output$map <- renderTmap({

    tm_df()

  })
}

The ecoregions are not showing up and I am not even able to click on the pulldown window to display the ecoregions. However, I am able to see in the interactive map the layers button and am able to select and deselect the first ecoregion. How do I make the pulldown window with the pickerInput clickable and able to display the ecoregions? Is there an easier way to do this without using if statements? Thanks for your help! Edit: I updated my code to account for the filtered tm. However, in the interactive map on the shiny app it says Error: argument 'x' is missing, without any default.

  • Why do you create `tm_df` as reactive data yet try to map `tm`? Perhaps change `tm` to `tm_df()`? – r2evans May 14 '23 at 18:55
  • Thank you. I updated my code and still run into the same problem. I edited my code in this request to reflect the changes. – Wade Sedgwick May 14 '23 at 19:22

0 Answers0