0

I want to be able to link my leaflet map with plotly charts such that when I click on a marker on the map, the input id corresponding to the clicked marker is highlighted on the plotly chart. So far I have already created a reactive function for the map click. The challenge is how to link it to the highlight feature in plotly chart. Here is my code:

 #reactive event for map click
  map_click<-reactive({
    clk=input$maps2_marker_click
    if(!is.null(clk)){
      rev_filter<-final_data %>% filter(Kiosk_Id_number==clk$id)
      return(rev_filter)
    }
    else{
      return(final_data)
    }
  }) #end map reactive function

#percentage change compared to baseline chart
  output$stacked_plot2<-renderPlotly(
    ggplotly(
      ggplot(map_click(),aes(x=Id,y=Percentage_change_compared_to_baseline
      ))+
        geom_col(aes(fill=Water_point_type))+
        labs(
          x="Kiosk ID Number",
          y="Percentage change compared to baseline") +
        theme(
          axis.title=element_text(size=9),
          axis.text.x = element_text(angle = 90),
          panel.grid = element_blank()
        )
    ) %>%
      layout(legend = list(
        orientation = "h",x=0.1,y=-0.2
      )
      )
  ) 
brian
  • 75
  • 1
  • 8
  • @Florian you have implemented the highlight feature with a table, what about with plotly chart? – brian Jun 02 '20 at 09:16
  • Hi, can you include a [reproducible example](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example)? In general, it is better to do so than putting a link towards another question since the link might be broken in the future – bretauv Jun 02 '20 at 10:24

0 Answers0