【发布时间】:2017-08-30 18:38:49
【问题描述】:
我尝试使用 for 循环在 dygrapgh 函数中添加多个阴影。但我不能。
老实说,我找了一个多星期的解决方案,我真的找不到任何建议。
请帮忙!
我写了这段代码:
dg= reactive ({
dygraph(X1(), main ="interactive graph",
xlab = "time frame",
ylab = "records" ) %>% dyRangeSelector()
})
# I have a table for the shades to be added, it's defined with reactive
shade_tab=reactive({ df[df$Equipement==input$NameOfMachine,] })
# add shades
for( i in 1:nrow(shade_tab()))
{ dg()= dyShading(dg(), from= shade_tab()$Date[i],
to= shade_tab()$Date[i] + 24*60*60 ,
color = 'black')
}
output$dygraph <- renderDygraph({ dg() })
这是我尝试过的代码,但我总是收到错误消息。:
Warning: Error in .getReactiveEnvironment()$currentContext:
Operation not allowed without an active reactive context. (You tried to do
something that can only be done from inside a reactive expression or
observer.)
Stack trace (innermost first):
46: .getReactiveEnvironment()$currentContext
45: .dependents$register
44: shade_tab
43: nrow
42: server [C:\Users\Curiosity\Desktop\Shiny Interface/server.R#90]
1: runApp
Error in .getReactiveEnvironment()$currentContext() :
Operation not allowed without an active reactive context. (You tried to do
something that can only be done from inside a reactive expression or
observer.)
ERROR: [on_request_read] connection reset by peer
谢谢!
【问题讨论】:
-
您必须对另一个
reactive或observe中的reactive表达式进行操作 -
我做了另一个反应,但我得到了错误!你能更正代码吗?
-
您需要提供您使用的变量的样本数据:
X1(),df,input$NameOfMachine -
好的!请稍等
-
X1() 是一个 xts 对象 | G.pk --------------- | ---------------------- 2014-02-10 18:54:13 | 0.7210235 2014-02-10 19:22:11 | 0.7628376 2014-02-10 19:24:21 | 0.6971685 2014-02-11 09:01:32 | 0.4503746 2014-02-11 09:04:41 | 0.7056433 2014-02-11 09:22:57 | 0.7525473 日期 |页眉 ------ | ------ 细胞 |细胞
标签: r rstudio shiny shiny-server