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!
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!
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.