Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Conditional Panel - R Shiny

Tags:

r

shiny

I am planning to include a conditional panel in a Shiny app that I am building. 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:

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. 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!

like image 646
Dataminer Avatar asked Oct 20 '25 14:10

Dataminer


1 Answers

I just figured out a solution for this. Just realized that the condition is evaluated as a Java script expression. 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). When I use a single %, this works!

like image 168
Dataminer Avatar answered Oct 23 '25 03:10

Dataminer



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!