简体   繁体   English

条件面板 - R Shiny

[英]Conditional Panel - R Shiny

I am planning to include a conditional panel in a Shiny app that I am building. 我打算在我正在构建的Shiny应用程序中包含一个条件面板。 The panel is conditioned on the value of an input action button. 面板取决于输入操作按钮的值。

The intent is to use the action button as a "toggle" button, to toggle between a plot and a datatable. 目的是使用操作按钮作为“切换”按钮,在绘图和数据表之间切换。 Since the value of the button increments by 1 at every click, I tried doing something like this: 由于按钮的值在每次点击时递增1,我尝试做类似这样的事情:

conditionalPanel(
                 condition = " input.<action_button_name> %% 2 == 0 ",
                 plotOutput("plot_id")),
conditionalPanel(
                 condition = " input.<action_button_name> %% 2 != 0 ",
                 dataTableOutput("datatable_id"))

This doesn't work. 这不起作用。 I tried exploring reactiveValues but that didn't work either. 我尝试过探索reactiveValues但这也没有用。 This is fairly straight forward to do with radio buttons (which is what I usually do), but I wanted specifically an action button in this case. 这与单选按钮(这是我通常做的)相当直接,但在这种情况下我特别想要一个动作按钮。

Is it do-able? 可以吗?

Thanks! 谢谢!

I just figured out a solution for this. 我刚刚想出了一个解决方案。 Just realized that the condition is evaluated as a Java script expression. 刚刚意识到条件被评估为Java脚本表达式。 While I don't know JS, a little googling gave me the modulus function.It's a single % sign (and not 2, like in R). 虽然我不懂JS,但有点谷歌搜索给了我模数函数。这是一个%符号(而不是2,就像在R中)。 When I use a single %, this works! 当我使用单个%时,这有效!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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