shiny: handling several conditional tableOutputs

Hello all,

I am struggling with a very small detail here that should be very easy to fixe but still couldn't fix it properly.

I have a button 'button1". When I click it, I would like table1 to be calculated and shown on the screen and then I would like to calculate table2 and show it on the screen.

My basic code is as follow:

conditionalPanel(condition = 'input.button1 > 0', tableOutput("table1")),
conditionalPanel(condition = 'input.button1 > 0', tableOutput("table2"))

However the first table is not shown on the screen before the second is calculated, which makes the waiting time quite long.

Can you help with this please?

Regards,

Maxime

Hi Maxime,

As far as my understanding goes, Shiny will only update the UI when the server is done with all calculations after an event is triggered, regardless of the order of the code. In your case, the fact you update table1 before table2 calculations start will not make it appear as you order it in the same event.

A simple fix is to make table 2 have a separate button, so you can calculate 1, then click two.

Hope this helpw,
PJ

Hi PJ,

Thanks for your answer.

Is there anyway to render the second table only once the first has been rendered without adding any button?
The second table makes sense only once the first has been obtained...

Regards,

Maxime

Hi,

I'm afraid that (to my knowledge) that is not possible.

You must look at it from Shiny's general perspective (this is not a very technical explanation beware :slight_smile: ): If several things need to be updated in one user action, the output should all appear at once to avoid conflicting results. In your case that wouldn't be an issue if table 1 appeared before 2, but imagine the code for creating table 2 would alter parameters that influenced table 1, then table one would have incorrect output if rendered before table 2 was finished and needed to be updated again once 2 finished.

In short, I think you have to choose: 1 click and wait, or two clicks and have table 1 first. It doesn't need to be a button, you can also create tabs or something, as long as table two is triggered by something else than table 1.

Again, there might be Shiny experts on here who would know a workaround, so this is just what I got from my experience with it...

PJ

Thanks, well then I suppose I can create a condition button2 based on the button1 being clicked :slight_smile: At least the button2 would appear only when table1 is rendered...

Just thinking out loud but thank you very much PJ for the shared reflexion!
Have a nice day,

Maxime

1 Like

This topic was automatically closed 54 days after the last reply. New replies are no longer allowed.