简体   繁体   English

在高图闪亮R中拖动和缩放散点图

[英]drag and zoom scatter plot in highcharts shiny R

I'm trying to create a scatter plot in which I could be able to drag an area and see in a table the data from the dragged points as also as to zoom in that specific area. 我正在尝试创建一个散点图,在其中可以拖动一个区域并在表中查看来自拖动点的数据,以及放大该特定区域。

After a research on the internet, I came to a solution with gglopt2 which works nice (presented next) and performs all the features I described. 经过对互联网的研究,我找到了gglopt2的解决方案,该解决方案很好用(接下来介绍)并执行了我描述的所有功能。

Now I'm wondering if I could do the same using the highcharts package on shiny R. I searched on the internet but I found no solution to my problem. 现在,我想知道是否可以使用发亮的R上的highcharts包来做同样的事情。我在互联网上进行搜索,但没有找到解决问题的方法。 Could someone help me on this? 有人可以帮我吗?

Thanks in advance 提前致谢

library(ggplot2)


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

  # global variable, what type of plot interaction
  interaction_type <- "click"

  # observe for user interaction and change the global interaction_type
  # variable
  observeEvent(input$user_click, interaction_type <<- "click")
  observeEvent(input$user_brush, interaction_type <<- "brush")

  observeEvent(input$plot1_dblclick, {
    brush <- input$user_brush
    if (!is.null(brush)) {
      ranges$x <- c(brush$xmin, brush$xmax)
      ranges$y <- c(brush$ymin, brush$ymax)

    } else {
      ranges$x <- NULL
      ranges$y <- NULL
    }
  })



  output$plot <- renderPlot({
    ggplot(mtcars, aes(wt, mpg)) + geom_point()
  })

  # generate the data to put in the table
  dat <- reactive({

    user_brush <- input$user_brush
    user_click <- input$user_click

    if(interaction_type == "brush") res <- brushedPoints(mtcars, user_brush)
    if(interaction_type == "click") res <- nearPoints(mtcars, user_click, threshold = 10, maxpoints = 1)

    return(res)

  })

  output$table <- DT::renderDataTable(DT::datatable(dat()[,c("mpg", "cyl", "disp")]))

}


ui <- fluidPage(

  h3("Click or brush the plot and it will filter the table"),
  plotOutput("plot", click = "user_click", dblclick = "plot1_dblclick", brush = brushOpts(  id = "user_brush",   resetOnNew = TRUE       ) ),
  DT::dataTableOutput("table")

)

shinyApp(ui = ui, server = server)

You could add a simple wrapper that will allow panning in both vertical and horizontal ways. 您可以添加一个简单的包装器,该包装器将允许垂直和水平平移。 In afterSetExtremes events of axes you could get current extremes that could be passed to your table to filter data in the table. 在轴的afterSetExtremes事件中,您可以获得当前的极端值,该极端值可以传递到表中以过滤表中的数据。

Demo: http://jsfiddle.net/u9on8dbb/ 演示: http//jsfiddle.net/u9on8dbb/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM