0

I am creating a R Shiny application using a bike sharing data set. I would like to create circle markers that show the number of incoming rides per station for a specific user input date (date()).

First, I am calculating the number of trips per station in a reactive function using pipes and summarize(). In the circle markers I would then like to use the calculated n_trips as the label when you hover over a circle. However, even though I can take all non-calculated values as a circle label, using n_trips does return any label at all. How can I show the calculated value as my label for the circle markers?

filtered <- reactive ({df.trip %>%
filter(format(df.trip$starttime,"%Y-%m-%d") == date()) %>%
      group_by(from_station_id) %>%
      summarize(n_trips = n()) %>% 
      left_join(df.station, by = c("from_station_id" = "station_id")})``

output$secondExample <- renderLeaflet({
leaflet(filtered()) %>%
  addTiles(group="OSM") %>%#OSM is default tile providor
  addProviderTiles(providers$Stamen.TonerLite) %>%
  setView(lng=-122.335167,
    lat=47.619113,
    zoom=12.46)%>%
  addCircleMarkers(lng = ~long, lat = ~lat, weight = 1,label=~htmlEscape(n_trips), radius = ~n_trips)})``
astrofunkswag
  • 2,608
  • 12
  • 25
  • Please share your data. Since `df.trip` isn't defined, it is incredibly difficult for anyone to help you find a solution. Check out this link on how to produce a [reproducible example](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) if you're unsure of how to share the data – astrofunkswag Jan 12 '19 at 19:13
  • does it work if you substitute a variable that has only a few data points for the reactive expression `filtered()`? Say you define a variable by `test <- data.frame("lan" = c(...), "lat" = c(...), "n_trips" = c(...))` at the beginning of your `renderLeaflet` function and use that as the input for `leaflet` function. – lkq Jan 12 '19 at 23:34

0 Answers0