0

On my local version of the code i am able to use the mapedit package to draw a rectangle or a different shape with the mapedit package on a leaflet map. With a spatial join i can then select all the data in the area and plot it. However when i uploaded the app to shiny it let me draw a rectangle but throws an error message everytime i click finished and does not display the selected data. The errormessage says st_crs(x) is not equal st_crs(y). However i tested this and this is not the case. Everything else works. So all the data can be displayed on the leaflet map and the filter also work.

UI:

ui = fluidPage(
  sidebarLayout(position = "left",
                sidebarPanel("Filter"),
                ),
                mainPanel( width=12,
                           fluidRow(
                             column(4, 
                                    selectInput("p1", "Plot accidents", c(colnames(bonn_heavy %>% select(c("UTYP1"))))),
                                    plotOutput("plot", height="21vh"), 
                                    selectInput("p2", "Plot property damage accidents", 
                             column(8, editModUI("map", height="58vh")) 
                           )
                )
  ))

Server

server <- function(input, output, session){
map <- leaflet() %>%  addTiles() %>% addSearchOSM(options = searchOptions(collapsed = TRUE)) %>% addDrawToolbar(
        polylineOptions = FALSE,
        circleOptions = FALSE,
        circleMarkerOptions = FALSE,
        markerOptions = FALSE,
        editOptions = editToolbarOptions(),
        singleFeature = TRUE) %>% addMarkers(data=accidents)

drawn = callModule(editMod, "map", map)
output$plot <- renderPlot({
    req(drawn()$finished)
    selected_accidents = st_join(filtered(), drawn()$finished, left=FALSE)
    counts = selected_accidents %>% st_drop_geometry() %>% select(input$p1) %>% table()
    barplot(counts, main="Personenschäden", xlab=input$p1, col="#5374e7")
  })
Thomas231
  • 45
  • 1
  • 7

0 Answers0