[英]Setting the interaction model of a Dygraph in Shiny for R
我正在将“自定义交互模型”下位于http://dygraphs.com/gallery/#g/interaction的自定义交互添加到我的Shiny Web应用程序中。
据我了解,这需要在页面上附加一些JS并在图形上设置交互模型:
interactionModel : { 'mousedown' : downV3, 'mousemove' : moveV3, 'mouseup' : upV3, 'click' : clickV3, 'dblclick' : dblClickV3, 'mousewheel' : scrollV3 }
但是,在R侧的dyOptions
函数中,似乎没有将interactionModel
作为参数列出。
有办法解决这个问题吗?
更新:
查看dyOptions
的来源,似乎可以直接修改选项:
g <- dyGraph(series)
g$x$attr$option <- "Value"
但是,在此处设置interactionModel
似乎无效。
参见: https : //github.com/rstudio/dygraphs/blob/master/R/options.R
更新:
您确实可以使用以下方法设置选项:
g$x$attrs$option <- "Value" # Note that it is "attrs", not "attr"
这可以用来关闭交互模式:
graph$x$attrs$interactionModel <- "{}"
剩下的问题是通过JSON将JS函数引用传递给页面。
您可以使用JS函数将JavaScript通过JSON传递给客户端。
在ui.R中:
tags$head(tags$script(src="interaction.js"))
在server.R中:
g <- dygraph(series(), main = "Graph", xlab = "Date", ylab = "Amount") %>%
dySeries(label = "X")
g$x$attrs$interactionModel <- list(
mousedown = JS("downV3"),
mousemove = JS("moveV3"),
mouseup = JS("upV3"),
click = JS("clickV3"),
dblclick = JS("dblClickV3"),
mousewheel = JS("scrollV3"))
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.