在Shiny for R中设置Dygraph的交互模型 [英] Setting the interaction model of a Dygraph in Shiny for R

查看:106
本文介绍了在Shiny for R中设置Dygraph的交互模型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望添加在 http://dygraphs.com/gallery/#上看到的自定义交互g/interaction (位于自定义交互模型"下)进入我的Shiny Web应用程序.

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.

据我了解,这需要在页面上附加一些JS并在图形上设置交互模型:

As far as I understand it, this requires attaching some JS to the page and setting the interaction model on the graph:

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

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

但是,在R侧的dyOptions函数中,似乎没有将interactionModel列为参数.

However, interactionModel does not seem to be listed as a parameter in the dyOptions function on the R side.

是否可以解决此问题?

更新:

查看dyOptions的来源,似乎可以直接修改选项:

Looking at the source for dyOptions, it seems that options can be modified directly:

g <- dyGraph(series)

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

但是,在此处设置interactionModel似乎无效.

However, setting the interactionModel here does not seem to work.

请参阅: https://github.com/rstudio/dygraphs/blob/master/R/options.R

更新:

您确实可以使用以下选项设置选项:

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 <- "{}"

剩下的问题是通过JSON将JS函数引用传递给页面.

The remaining problem is passing JS function references via JSON to the page.

推荐答案

您可以使用JS函数通过JSON将JavaScript传递给客户端.

You can use the JS function to pass JavaScript over JSON to the client.

在ui.R中:

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

在server.R中:

In 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"))

这篇关于在Shiny for R中设置Dygraph的交互模型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆