2016-11-08 6 views
2

サンプルコードを実行してください。R Shiny:ggplot2でのブラシ機能の異常な動作

散布図の点を選択すると、選択した点がグラフから削除されます。それ以外はほとんどうまくいっていますが、チャートのコーナーの近くでいくつかのポイントを選択すると、クイックダブル自己更新の後にこれらのポイントが戻ってきます。

チャートの中央にあるポイントについては、うまくいきました。この奇妙な動作を説明するための方法

enter image description here

library(ggplot2) 
library(shiny) 

server <- function(input, output) { 

    vals = reactiveValues(keeprows = TRUE) 

    observeEvent(input$brush_1,{ 
    cat("---------------\n") 
    print("brush_1") 
    Res = brushedPoints(mtcars,brush = input$brush_1,allRows = TRUE) 
    vals$keeprows = !Res$selected_  
    }) 

    observeEvent(input$brush_2,{ 
    cat("---------------\n") 
    print("brush_2") 
    Res = brushedPoints(mtcars,brush = input$brush_2,allRows = TRUE) 
    vals$keeprows = !Res$selected_  
    }) 

    D = reactive({ 
    print("D") 
    mtcars[vals$keeprows,] 
    }) 

    output$p1 = renderPlot({ 
    print("plot_1") 
    X = D() 
    ggplot(X,aes(x=mpg,y=cyl))+geom_point() 
    }) 
    output$p2 = renderPlot({ 
    print("plot_2") 

    ggplot(D(),aes(x=mpg,y=wt))+geom_point() 
    }) 

    output$L = renderPrint({ 
    Res = brushedPoints(mtcars,brush = input$brush_1,allRows = TRUE) 
    Res 
    }) 
} 


ui <- fluidPage(
    splitLayout(plotOutput("p1",brush = "brush_1"),plotOutput("p2",brush = "brush_2")) 
       , 
    verbatimTextOutput("L") 
) 


shinyApp(ui = ui, server = server) 

brush_1イベントが二回起動され、それらの奇妙なポイントを選択した場合にプロットがリセットされているようです。あなたはプロット上の修正の制限を設定することができます

答えて

3

空間全体に合うように再描画されるので、あなたは、プロットの限界点を選択解除し、これはブラシの設定を解除するときに問題が起こります...それを防止する:

ggplot(X,aes(x=mpg,y=cyl))+ 
geom_point()+ 
scale_x_continuous(limits=c(min(mtcars$mpg),max(mtcars$mpg)))+ 
scale_y_continuous(limits=c(min(mtcars$cyl),max(mtcars$cyl))) 
+0

ありがとう。それは完璧だ。 – John

関連する問題