2
サンプルコードを実行してください。R Shiny:ggplot2でのブラシ機能の異常な動作
散布図の点を選択すると、選択した点がグラフから削除されます。それ以外はほとんどうまくいっていますが、チャートのコーナーの近くでいくつかのポイントを選択すると、クイックダブル自己更新の後にこれらのポイントが戻ってきます。
チャートの中央にあるポイントについては、うまくいきました。この奇妙な動作を説明するための方法
?
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
イベントが二回起動され、それらの奇妙なポイントを選択した場合にプロットがリセットされているようです。あなたはプロット上の修正の制限を設定することができます
ありがとう。それは完璧だ。 – John