Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/r/80.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在r传单中实现地图单击事件并将事件重置为默认值?_R_Shiny Reactivity_R Leaflet - Fatal编程技术网

如何在r传单中实现地图单击事件并将事件重置为默认值?

如何在r传单中实现地图单击事件并将事件重置为默认值?,r,shiny-reactivity,r-leaflet,R,Shiny Reactivity,R Leaflet,我想在我的地图中实现两个地图点击事件:地图标记点击和地图点击。当我单击地图上的一个标记(使用map\u marker\u click)时,我希望事件根据单击的标记的id过滤其他相关图表。使用map_click事件通过单击底图,我希望该事件将地图和图形重置为默认值(使用所有标记和图表)。 使用我当前的代码,我只能单击一个标记,并且只有该标记与相应的图表一起显示在地图上。 这是我的密码: #reactive event for map click map_click<-reactive(

我想在我的地图中实现两个地图点击事件:地图标记点击和地图点击。当我单击地图上的一个标记(使用map\u marker\u click)时,我希望事件根据单击的标记的id过滤其他相关图表。使用map_click事件通过单击底图,我希望该事件将地图和图形重置为默认值(使用所有标记和图表)。 使用我当前的代码,我只能单击一个标记,并且只有该标记与相应的图表一起显示在地图上。 这是我的密码:

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


   #color function for waterpoint types
  pal=colorFactor(c("sienna2","green3","cornflowerblue"),domain = final_data$Water_point_type)

  #interactive map with click event
  output$maps2<-renderLeaflet(
    leaflet() %>%
      addCircleMarkers(
        data = map_click(),
        fillColor = ~pal(Water_point_type),
        fillOpacity = 1.0,
        radius = 8,
        stroke = FALSE,
        lat = ~latitude,
        lng = ~longitude,
        layerId = ~Kiosk_Id_number
  ) #end renderleaflet


  #facet plots 
  #plots are filtered based on the map click
  output$facet_plot<-renderPlotly(
    ggplotly(
      ggplot(map_click(),aes(x=Day,y=Daily_revenue,group=Kiosk_Id_number))+
        geom_col(aes(fill=Water_point_type))+
        scale_fill_manual(values = c("sienna2","cornflowerblue")
        )+
        geom_line(aes(y=Daily_Average),linetype="dashed", size=0.4,color="gray0")+
        facet_wrap(~Kiosk_Id_number,scales = "free_y",ncol = 2)+
        labs(
          y="Daily Average Revenue (GHC)")+
        scale_x_discrete(breaks=c("05-Jun-19","31-Jul-19",
                                  "27-Sep-19","28-Nov-19","31-Dec-19",
                                  "31-Jan-20","28-Feb-20","26-Mar-20"))+
        scale_y_continuous(breaks = my_breaks)+
        theme(axis.text.x = element_text(angle = 90,size = 7),
              axis.title = element_text(size=9),
              axis.text = element_text(face = "bold"),
              axis.title.x = element_blank(),
              axis.text.y = element_text(size=6,face="bold"),
              strip.text = element_text(face="bold"),
              strip.background = element_blank(),
              strip.text.x = element_text(face="bold.italic",colour ="gray0",size=8,margin=margin(0,0,0,0,"cm")),
              legend.title = element_blank(),
              #legend.position = "bottom",
              panel.grid = element_blank(),
              panel.spacing = unit(2, "lines")       
        )  
    ) 
  )#end renderplot
#地图点击的反应事件
地图点击