2016-11-08 15 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) 

IT는 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