有光泽:将reactiveValues传递给conditionalPanel [英] shiny: passing reactiveValues to conditionalPanel

查看:808
本文介绍了有光泽:将reactiveValues传递给conditionalPanel的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我可以将reactiveValues传递给conditionalPanel的条件吗?如果是这样,怎么样?



这是我在conditionalPanel中尝试过的ui.R:

  conditionalPanel(condition =values.cond == 0等等。

我已经在server.R中定义了值$ cond

 值<  -  reactiveValues(cond = 0)

我也尝试过类似values.cond == true,但没有成功。

  library(shiny) 
runGist(https://gist.github.com/anonymous/8281021)

参见代码:



https:// gist .github.com / anonymous / 8281021

解决方案

正如@jdharrison指出的,你有问题,你有反应性或服务器端的任何其他数据,条件面板是JS条件+客户端的一些HTML。因此,如果y您希望根据您在服务器端计算的某些值动态更新JS条件,您需要将数据从服务器获取到客户端。我认为你可以做的是使用一个仍然没有文档的闪亮功能来将自定义数据从服务器传递到客户端。我写了一篇关于如何做到这一点的博客文章: http://ryouready.wordpress.com/2013/11/20/sending-data-from-client-to-server-and-back-using-shiny/



我想您可以使用该方法动态更新JS面板条件。您需要编写一个JS函数,在传递数据后执行此操作。因此,这归结为使用您想要的值替换 conditionalPanel 输出的 data-display-if 属性。 / p>

另一个想法:如果您的UI强烈依赖于服务器端的计算,您可能需要考虑使用<$动态创建(侧边栏)内容c $ c> renderUI 。



编辑:顺便说一句,这就是@jdharrison在他的第二条评论中提到的。


Can I pass a reactiveValues to a conditionalPanel's condition? If so, how?

Here is what I have tried in the conditionalPanel ui.R:

conditionalPanel(condition = "values.cond == 0", etc.

where I have defined values$cond in server.R:

values <- reactiveValues(cond = 0)

I have also tried alternatives like "values.cond == true", without success.

library("shiny")
runGist("https://gist.github.com/anonymous/8281021")

See the code:

https://gist.github.com/anonymous/8281021

解决方案

As @jdharrison pointed out, you have the problem, that you have reactive values or any other data on the server side and the conditional panel is a JS condition + some HTML on the client side. Hence, if you want to dynamically update the JS condition according to some value you calculated on the server side, you need to get the data from the server to the client. I think what you could do is use an still undocumented feature of shiny to pass custom data from the server to the client. I wrote a blog post on how to do that: http://ryouready.wordpress.com/2013/11/20/sending-data-from-client-to-server-and-back-using-shiny/

I guess you could use that approach to dynamically update the JS panel condition. You would need to write a JS function that does this after the data has been passed. So this boils down to replacing the data-display-if attribute of the conditionalPanel output with the values you want.

Another idea: If your UI strongly depends on calculations on the server side you may want to consider creating the (sidebar) content dynamically using renderUI.

EDIT: Btw, that's what @jdharrison referred to in his second comment.

这篇关于有光泽:将reactiveValues传递给conditionalPanel的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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