Shiny app and filter

I have written a shiny app and a filter for selecting a determined input. I have always used this code and usually it's works but this time I have a problem. If I delete this row: Legend <- Legend %>% filter(Legend$col1 == input$magazzino) the shiny app works but obviously the filter does not. Also If I run the code without run before Legend if I have another error. I don't understand where I am wrong.

  function(input, output, session) {
  dati1 <- c("a - Novara Delete", "b - Torino Trash", "c - Milano", "f - Bari")
  prov_ita <- rgdal::readOGR("")

  Legend <- tidyr::separate(data.frame(dati1), col = dati1, into = str_c("col", 1:2), extra = 'drop')
    magazzino <- reactive({
      filter(Legend, col1 == input$magazzino)
      points <- eventReactive(input$recalc, {
        cbind(rnorm(40) * 2 + 13, rnorm(40) + 48)
      }, ignoreNULL = FALSE)
      Legend <- Legend %>% filter(Legend$col1 == input$magazzino)
      citta_new <- geocode_OSM(unique(Legend$col2))
      citta_new <- merge(citta_new, Legend, by.x="query", by.y="col2")
      citta.sf <- arrange(citta_new %>% st_as_sf(coords = c("lon", "lat"), crs = 4326))
      output$mymap <- renderLeaflet({
        leaflet(prov_ita) %>% addTiles() %>%
          addMarkers(data = citta.sf, label = (citta_new$query))


shinyUI (fluidPage(
  navbarPage("My Application",
             tabPanel("Magazzino di Partenza",
                      selectInput("magazzino", "Magazzino di Partenza", choices = unique(Legend$col1)),


I haven't checked your example code below but this one line shows an incorrect use of dplyr::filter. when you use filter, and the data argument is set (i.e. its Legend) then if you want to 'use' a column from the data, you should not repeat the data.frame name and pull out the column with $ syntax.
So I would expect perhaps:

Legend <- Legend %>% filter(col1 == input$magazzino)

looking at your code, you have correctly made magazzino reactive in this way.
Yet you don't seem to use that anywhere, i.e. theres no magazzino() later in your code, where your definition is put to use.

I will try to correct and adjust the code but now I have see that the read xls don't work. Do you see some error? I have always write the code in this way

Im confused, 'xls' doesnt appear anywhere in the code you shared.

1 Like

Sorry, I mean read_excel and you are right I have remove because I can't upload the file.

Also I need to use my dataset for all the code, my output must be a map using a coordinate of one city that I select using a filter. I have create this code and also used last time, I don't understand why now it doesn't work