到目前为止,我正在构建一个shiny
应用程序,其简化如下。
library(shiny)
foo <- function(draggable = FALSE) {
ui <- shinyUI(
bootstrapPage(
absolutePanel(
id = "controls",
class = "panel panel-default",
draggable = draggable,
width = 330,
height = "auto",
plotOutput(outputId="plots",
brush = brushOpts(id = "plot_brush",
resetOnNew = FALSE),
dblclick = "plot_click")
)
)
)
server <- shinyServer(function(input, output, session) {
x <- mtcars$mpg
y <- mtcars$hp
highlightColor <- "red"
output$plots <- renderPlot({
plot(x = x, y = y)
brush <- input$plot_brush
if(!is.null(brush)) {
id <- intersect(
which(x >= brush$xmin & x <= brush$xmax),
which(y >= brush$ymin & y <= brush$ymax)
)
xx <- x[id]
yy <- y[id]
points(xx, yy ,col = highlightColor)
}
})
})
shinyApp(ui = ui, server = server)
}
图中的点可以通过笔刷突出显示。同时,我也想使该图可拖动。但是,如果该图是可拖动的,则无法再对其进行刷刷。
# the plot cannot be dragged, but the brush works fine
foo(draggable = FALSE)
# the plot can be dragged, but the brush does **not** work
foo(draggable = TRUE)
所以我想知道,是否有可能在不牺牲涂刷功能的情况下使图形可拖动? (例如,当光标到达图形的边缘时,请按向左键,然后可以拖动图;如果光标位于图内,请按向左键,可以刷图)