R 链接传单';s图标以图形方式绘制线条打印

R 链接传单';s图标以图形方式绘制线条打印,r,shiny,leaflet,plotly,R,Shiny,Leaflet,Plotly,我希望传单地图上的图标链接到闪亮应用程序中绘图线图上相应的轨迹。单击图标后,只有具有相同id的行才会显示在中。这可能吗?我一直在尝试串扰,但我肯定错过了什么 library(shiny) library(leaflet) library(plotly) library(crosstalk) tmp1 <- data.frame(Date = seq(as.POSIXct("2016-06-18 10:00"), length.

我希望
传单
地图上的图标链接到闪亮应用程序中
绘图
线图上相应的轨迹。单击图标后,只有具有相同id的行才会显示在
中。这可能吗?我一直在尝试
串扰
,但我肯定错过了什么

library(shiny)
library(leaflet)
library(plotly)
library(crosstalk)


tmp1 <- data.frame(Date = seq(as.POSIXct("2016-06-18 10:00"),
                              length.out = 10, by = "mins"),
                   Temp = rnorm(n = 10, mean = 20, sd = 5),
                   lat=51.504162, 
                   long=-0.130472,
                   id="first") 
tmp2 <- data.frame(Date = seq(as.POSIXct("2016-06-18 10:00"),
                              length.out = 10, by = "mins"),
                   Temp = rnorm(n = 10, mean = 20, sd = 5),
                   lat=51.502858,
                   long= -0.116722,
                   id="second") 

uktemp<-rbind(tmp1,tmp2)

#=========================================

ui <- fluidPage(
  fluidRow(
    column(6, leafletOutput("map")),
    column(6, plotlyOutput("graph"))
  )
)

server <- function(input, output, session) {
  crossuktemp<- SharedData$new(uktemp)

  output$map <- renderLeaflet({
    leaflet(options = leafletOptions(minZoom = 15,maxZoom =18 ))%>%
      addTiles()%>%
      addCircles(data=crossuktemp,
                 lng= ~ long,
                 lat= ~ lat,
                 label=~id)
  })

  output$graph <- renderPlotly({
    plot_ly(crossuktemp,x=~Date,y=~Temp, color =~id, mode="lines")%>%
      layout(title = "",yaxis = list(title = "C°"), 
             xaxis = list(title = "Time")) %>%
      highlight(off = "plotly_deselect") 
  })
}

shinyApp(ui, server)
库(闪亮)
图书馆(单张)
图书馆(绘本)
图书馆(串扰)

tmp1我已经拼凑出一个解决方案,利用它在点击时创建的传单事件

ui <- fluidPage(
  # add a reset button to undo click event
  fluidRow(actionButton("reset", "Reset")),
  fluidRow(
    column(6, leafletOutput("map")),
    column(6, plotlyOutput("graph"))
  ),
  fluidRow()
)

server <- function(input, output, session) {

  # create reactive data set based on map click
  filteredData <- reactive({
    event <- input$map_shape_click
    if (!is.null(event)){
      uktemp[uktemp$lat == event$lat & uktemp$long == event$lng,]
    }
  })

  output$map <- renderLeaflet({
    leaflet(options = leafletOptions(minZoom = 15,maxZoom =18 ))%>%
      addTiles()%>%
      addCircles(data=crossuktemp,
                 lng= ~ long,
                 lat= ~ lat,
                 label=~id)
  })


  # default graph
  output$graph <- renderPlotly({
    plot_ly(uktemp,x=~Date,y=~Temp, color =~id, mode="lines")%>%
      layout(title = "",yaxis = list(title = "C°"), 
             xaxis = list(title = "Time")) %>%
      highlight(off = "plotly_deselect") 
  })

  # if clicked on map, use filtered data
  observeEvent(input$map_click,
               output$graph <- renderPlotly({
                 plot_ly(filteredData(),x=~Date,y=~Temp, color =~id, mode="lines")%>%
                   layout(title = "",yaxis = list(title = "C°"), 
                          xaxis = list(title = "Time")) %>%
                   highlight(off = "plotly_deselect") 
               })
  )

  # if reset, then go back to main data
  observeEvent(input$reset,

               output$graph <- renderPlotly({
                 plot_ly(uktemp,x=~Date,y=~Temp, color =~id, mode="lines")%>%
                   layout(title = "",yaxis = list(title = "C°"), 
                          xaxis = list(title = "Time")) %>%
                   highlight(off = "plotly_deselect") 
               })

  )

}
ui%
突出显示(off=“plotly\u deselect”)
})
)
}
为此,请阅读这些链接

请参阅“输入/事件”一节

有些是这样的问题

要撤消单击事件,我必须在中添加一个重置按钮。也许有一种方法可以更优雅地取消点击。如果你多读一些,我希望有更干净的方法来构建它:)

干杯,
Jonny

我利用它在点击时创建的传单事件,拼凑出了一个解决方案

ui <- fluidPage(
  # add a reset button to undo click event
  fluidRow(actionButton("reset", "Reset")),
  fluidRow(
    column(6, leafletOutput("map")),
    column(6, plotlyOutput("graph"))
  ),
  fluidRow()
)

server <- function(input, output, session) {

  # create reactive data set based on map click
  filteredData <- reactive({
    event <- input$map_shape_click
    if (!is.null(event)){
      uktemp[uktemp$lat == event$lat & uktemp$long == event$lng,]
    }
  })

  output$map <- renderLeaflet({
    leaflet(options = leafletOptions(minZoom = 15,maxZoom =18 ))%>%
      addTiles()%>%
      addCircles(data=crossuktemp,
                 lng= ~ long,
                 lat= ~ lat,
                 label=~id)
  })


  # default graph
  output$graph <- renderPlotly({
    plot_ly(uktemp,x=~Date,y=~Temp, color =~id, mode="lines")%>%
      layout(title = "",yaxis = list(title = "C°"), 
             xaxis = list(title = "Time")) %>%
      highlight(off = "plotly_deselect") 
  })

  # if clicked on map, use filtered data
  observeEvent(input$map_click,
               output$graph <- renderPlotly({
                 plot_ly(filteredData(),x=~Date,y=~Temp, color =~id, mode="lines")%>%
                   layout(title = "",yaxis = list(title = "C°"), 
                          xaxis = list(title = "Time")) %>%
                   highlight(off = "plotly_deselect") 
               })
  )

  # if reset, then go back to main data
  observeEvent(input$reset,

               output$graph <- renderPlotly({
                 plot_ly(uktemp,x=~Date,y=~Temp, color =~id, mode="lines")%>%
                   layout(title = "",yaxis = list(title = "C°"), 
                          xaxis = list(title = "Time")) %>%
                   highlight(off = "plotly_deselect") 
               })

  )

}
ui%
突出显示(off=“plotly\u deselect”)
})
)
}
为此,请阅读这些链接

请参阅“输入/事件”一节

有些是这样的问题

要撤消单击事件,我必须在中添加一个重置按钮。也许有一种方法可以更优雅地取消点击。如果你多读一些,我希望有更干净的方法来构建它:)

干杯, 琼尼