Shiny app and Input Variabile

I have done this shiny app, only my second (I think there are a lot errors), and it isn't work well. I need to use select input in this way: when I select city I need to the city and the client the city served. So if I select Novara I will see Genova and Bologna on the map. Where am I wrong?

SERVER

library(readxl)
city <- c("Novara", "Novara","Novara","Novara","Brindisi","Brindisi","Brindisi")
client <- c("Genova", "Genova","Bologna","Bologna","Bologna","Empoli","Catania")
dimension <- as.numeric(c("15000", "5000","3000","4600","3400","6700","3400"))

Dati <- data.frame(city,client,dimension)
prov_ita <- rgdal::readOGR("https://raw.githubusercontent.com/openpolis/geojson-italy/master/geojson/limits_IT_provinces.geojson")


shinyServer(
  function(input, output, session) {
    
    magazzino <- reactive({
      filter(Dati, city == input$magazzino)
    })
    
    observeEvent(input$magazzino,{
      points <- eventReactive(input$recalc, {
        cbind(rnorm(40) * 2 + 13, rnorm(40) + 48)
      }, ignoreNULL = FALSE)
      
      options(dplyr.summarise.inform = FALSE)
      a <- client 
      b <- dimension
      VendutoPerProvincie<- data.frame(a,b)
      
      VendutoPerProvincie %>% 
        group_by(a) %>% 
        summarise(d = sum(b)) %>% 
        ungroup()
      
      citta_new <- geocode_OSM(unique(Dati$city))
      
      citta.sf <- arrange(citta_new %>% st_as_sf(coords = c("lon", "lat"), crs = 4326))
      citta.buffer <- arrange(citta.sf %>% sf::st_buffer(dist = 0))
      
      pal <- colorNumeric("viridis", NULL)
      
      prov_ita@data = data.frame(prov_ita@data,
                                 VendutoPerProvincie[match(prov_ita@data[, "prov_name"],
                                                           VendutoPerProvincie[, "a"]),])
      
      
      output$mymap <- renderLeaflet({
        leaflet(prov_ita) %>% addTiles() %>%
          addMarkers(data = citta.sf, label = unique(citta_new$query)) %>%
          addPolygons(stroke = TRUE, smoothFactor = 0.3, fillOpacity = 1,
                      fillColor = ~pal(prov_ita$b) , weight = 1, color = "black", label = prov_ita$prov_name)
      })
    })
  })

UI

library(shiny)
library(leaflet)
library(tmaptools)
library(sf)
library(leaflet)
library(readxl)
library(dplyr)
library(DT)

shinyUI (fluidPage(
  
  selectInput("magazzino", "Magazzino_di_Partenza", choices = unique(Dati$client)),
  
  leafletOutput("mymap"),
  p(),
  
)
)

This topic was automatically closed 54 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.