如何在R中使用绘图选择从数据表中选择行

如何在R中使用绘图选择从数据表中选择行,r,shiny,plotly,R,Shiny,Plotly,我有一个Plotly ggplotly图形,用户可以通过单击或刷牙从中选择点。我想向用户显示数据表中的选定点。我使用以下代码定义输出: dataTableOutput("selectedPoints") 我试图用下面的代码以数据帧的形式返回所选的点,但它不起作用 myPlot <- ggplotly(ggplot(variableDataAnalysisPlots$dataToMelt, aes_string(x = 'LDT', y = input$men

我有一个Plotly ggplotly图形,用户可以通过单击或刷牙从中选择点。我想向用户显示数据表中的选定点。我使用以下代码定义输出:

dataTableOutput("selectedPoints")
我试图用下面的代码以数据帧的形式返回所选的点,但它不起作用

     myPlot <- ggplotly(ggplot(variableDataAnalysisPlots$dataToMelt, aes_string(x = 'LDT', y = input$menuAnalysisPlots[[1]])) +
                                            geom_point(size = 1) + theme(axis.text = element_text(size = rel(1.25), face = "bold")) +
                                            theme(axis.title = element_text(size = rel(1.25), face = "bold")) +
                                            ggtitle(paste0("5 Minute Data Time Series for ", colnames(variableDataAnalysisPlots$dataToMelt)[2])) +
                                            theme(plot.title = element_text(size = rel(1.50), face = "bold", hjust = 0.5)))
  
  myPlot %>% 
    layout(dragmode = "select") %>%
    event_register(event = "plotly_selecting")
   
  output$click <- renderPrint({
    d <- event_data("plotly_click")
    if (is.null(d)) "Click events appear here (double-click to clear)" else d
  })
  
  output$brushed <- renderPrint({
    d <- event_data("plotly_brushed")
    if (is.null(d)) "Brush extents appear here (double-click to clear)" else d
  })
  
  output$selected <- renderPrint({
    d <- event_data("plotly_selected")
    if (is.null(d)) "Brushed points appear here (double-click to clear)" else d
  })
  
  
  output$selectedPoints <- renderDataTable({
    d
  })
myPlot%
布局(dragmode=“select”)%%>%
事件寄存器(event=“plotly\u selection”)

输出$click也许您应该使用
拖动画笔
。在本例中,它将显示表格。