I developed app to support my hydrological modelling teaching. In it, students can select a gauging station to work with. In order to enhance the amount of information the students get from the app, I decided to update it including a map that shows the station and its associated catchment on top of a national map, together with a more detailed map like this:
This is the code I am using (simplified to represent just my problem):
station_data <- read.csv("station_timeseries.csv",na.strings = "NaN",fileEncoding="UTF-8-BOM")
station_data$date <- as.Date(station_data$date,"%d/%m/%Y")
station_lat <- read.csv("station_coord.csv",fileEncoding="UTF-8-BOM")
GB_boundary <- st_read("./maps/GB_boundary.shp")
catchment_boundary <- st_read("./maps/Catchments.shp")
ui <- shinyUI(fluidPage(
  sidebarPanel(
    # Select station
    selectInput(inputId = "station", label = strong("Select station"),
                choices = unique(station_data$gauge_name))
    ),
  tabPanel("Catchment characteristics",plotOutput(outputId = "Map"))
)
)
server <- shinyServer(function(input, output) {
  ## Catchment and station map ----
  output$Map <- renderPlot({
    station <- station_lat[station_lat$gauge_name==input$Station,]$gauge_id
    bbox <- st_bbox(catchment_boundary[catchment_boundary$ID==station,])
    large_map <- ggplot()+
      geom_sf(data=GB_boundary,size=1,color="black",fill="cyan1")+
      geom_sf(data=catchment_boundary[catchment_boundary$ID==station,],size=1,color="black",fill="red")+
      theme_bw()
    detail_map <- ggplot()+
      geom_sf(data=GB_boundary,size=1,color="black",fill="cyan1")+
      geom_sf(data=catchment_boundary[catchment_boundary$ID==station,],size=1,color="black",fill="red")+
      coord_sf(xlim=c(bbox[1]-20000,bbox[3]+20000),ylim = c(bbox[2]-20000,bbox[4]+20000),expand = FALSE)+
      ggtitle("Catchment and station location")+
      theme_bw()
    grid.arrange(large_map,
                 detail_map,
                 ncol = 2,
                 widths = c(2,5))
  })
})
shinyApp(ui = ui, server = server)
I used the ggplot2 code you can see to generate the above image. However, when running the shiny app I get this:
It seems to me like shiny only reads the first geom_sf command and disregarding the next two plots. Does anyone have experienced something similar? Any suggestions to solve this?
Edit: I added links to the data used in this example, stations and both maps.
Cheers! David
