简体   繁体   English

在Shiny for R中设置Dygraph的交互模型

[英]Setting the interaction model of a Dygraph in Shiny for R

I am looking to add the custom interaction seen at http://dygraphs.com/gallery/#g/interaction under "Custom interaction model" into my Shiny web app. 我正在将“自定义交互模型”下位于http://dygraphs.com/gallery/#g/interaction的自定义交互添加到我的Shiny Web应用程序中。

As far as I understand it, this requires attaching some JS to the page and setting the interaction model on the graph: 据我了解,这需要在页面上附加一些JS并在图形上设置交互模型:

interactionModel : { 'mousedown' : downV3, 'mousemove' : moveV3, 'mouseup' : upV3, 'click' : clickV3, 'dblclick' : dblClickV3, 'mousewheel' : scrollV3 }

However, interactionModel does not seem to be listed as a parameter in the dyOptions function on the R side. 但是,在R侧的dyOptions函数中,似乎没有将interactionModel作为参数列出。

Is there a way to work around this? 有办法解决这个问题吗?

Update: 更新:

Looking at the source for dyOptions , it seems that options can be modified directly: 查看dyOptions的来源,似乎可以直接修改选项:

g <- dyGraph(series)

g$x$attr$option <- "Value"

However, setting the interactionModel here does not seem to work. 但是,在此处设置interactionModel似乎无效。

See: https://github.com/rstudio/dygraphs/blob/master/R/options.R 参见: https : //github.com/rstudio/dygraphs/blob/master/R/options.R

Update: 更新:

You can indeed set the options using: 您确实可以使用以下方法设置选项:

g$x$attrs$option <- "Value" # Note that it is "attrs", not "attr"

This can be used to switch off the interaction mode: 这可以用来关闭交互模式:

graph$x$attrs$interactionModel <- "{}"

The remaining problem is passing JS function references via JSON to the page. 剩下的问题是通过JSON将JS函数引用传递给页面。

You can use the JS function to pass JavaScript over JSON to the client. 您可以使用JS函数将JavaScript通过JSON传递给客户端。

In ui.R: 在ui.R中:

tags$head(tags$script(src="interaction.js"))

In server.R: 在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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM