2016-09-15 15 views
0

散布図を作成しようとしていますが、領域をドラッグしてドラッグした点のデータを表で見ることができますエリア。ハイチャートの散布図をドラッグして拡大表示するR

インターネットでの調査の後、私はgglopt2を使って解決策を見つけました(次に提示される)、私が説明したすべての機能を実行します。

光沢のあるRでhighchartsパッケージを使用して同じことができるかどうかは疑問です。私はインターネットで検索しましたが、私の問題は解決されませんでした。誰かが私を助けてくれましたか?事前

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) 

答えて

0

おかげであなたは、両方の垂直方向と水平方向の方法でパンできるようになります単純なラッパーを追加することができます。軸のafterSetExtremesイベントでは、あなたのテーブルに渡されてテーブル内のデータをフィルタリングすることができる極端な現実を得ることができます。

デモ:http://jsfiddle.net/u9on8dbb/

関連する問題