3
votes

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!

1
fyi, the condition has to be a javascript expression, not R code. - talat
Yes..I just realized it myself! Posted a response.. - Dataminer

1 Answers

2
votes

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!