【发布时间】:2019-01-19 15:00:08
【问题描述】:
我有一个包含 Highcharter 图表的 Shiny 应用程序。该图是一个散点图,具有可拖动和可点击的点。理论上,与拖动相关的动作应该与与点击相关的动作互斥。
但是,实际上,点击操作有时会在拖动点时触发。在此应用程序中,仅单击(不拖动)和拖动(在释放鼠标按钮和完成拖动操作之前应该无法单击)需要相互排斥。根据事件的类型,我的完整代码有不同的 JavaScript 操作被传递回 Shiny 服务器。两个事件一起触发会造成麻烦。
我怀疑该解决方案涉及添加与每个事件相关的附加 JavaScript 操作。不过,我的 JavaScript 技能还不够强,无法知道这些调整可能是什么。谷歌搜索这个问题的几个不同变体并没有找到任何潜在的解决方案。我发现的最接近的讨论是在 Highcharts 上下文中,here,但解决方案与主 Highchart/draggable-events JS 文件有关。
建议?
对于一个玩具示例,您可以在其中看到这种行为:
rm(list=ls())
library(highcharter)
library(shiny)
ui <- fluidPage(
highchartOutput("hcontainer")
)
# MUTUAL EXCLUSIVITY:
# if you drag in the plot, you should either drag (and get no alert) OR
# get an alert (and the point shouldn't/won't move), but never both.
server <- function(input, output, session) {
output$hcontainer <- renderHighchart({
hc <- highchart() %>%
hc_chart(animation = FALSE) %>%
hc_title(text = "draggable points demo") %>%
hc_plotOptions(
series = list(
point = list(
events = list(
drop = JS("function(){ /* # do nothing, for demo */
}"
),
click = JS("function(){
alert('You clicked') /* # give alert, for demo */
}"
)
)
),
stickyTracking = FALSE
),
column = list(
stacking = "normal"
),
line = list(
cursor = "ns-resize"
)
) %>%
hc_tooltip(yDecimals = 2) %>%
hc_add_series(
type = "scatter",
data = stars,
draggableY = TRUE,
draggableX = TRUE,
hcaes(x = absmag, y=radiussun)
)
hc
})
}
shinyApp(ui = ui, server = server)
【问题讨论】:
-
我无法在纯 JS 中重现这个问题:jsfiddle.net/kkulig/z5y4b67e 你能提供一些关于这个问题的现场演示吗?
-
得到了复制:http://jsfiddle.net/m5wnnnm5/1/。拖动点时,在松开鼠标之前暂停一拍。它似乎与 scatter 有关,并且具有 x-draggable 点。此外,修复了初始帖子中的 R-Shiny 代码。它现在会运行,但问题仍然存在。
标签: highcharts shiny r-highcharter