Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

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

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
397 views
Welcome To Ask or Share your Answers For Others

1 Answer

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...