简体   繁体   中英

Shiny R: conditionalPanel and actionButton

I'm struggling to get my head around conditionalPanels.

Initially I want to show a panel with instructions on how to use the app (a tax calculator). Once users have changed the inputs to their specs and pressed Update the second conditionalPanel will show up.

Currently the app works for the first round, but then the count on the buttons increases beyond 0 and 1 rendering them useless.

Other posts suggest using isolate(), I'm not sure what I'm meant to be isolating in this context.

#buttons

actionButton(inputId = "updateButton",
                        label = "Update"),
           actionButton(inputId = "reset_button",
                        label = "Reset")

#conditional panels

conditionalPanel(
  condition = ("input.updateButton == 0"),
h3("Instructions for calculator"),
),
conditionalPanel(
  condition = "input.updateButton == 1",
  tabPanel(
    "Summary",
      h3("Outputs calculated based on user inputs"),
        )

If I have missed anything do call me out on it. Thanks.

You could try a hack using remainders like this:

First condition

("input.updateButton%2==0")

Second condition

("input.updateButton%2==1")

What about using input.updateButton != 0 as the condition for the second conditionalPanel?

#buttons

actionButton(inputId = "updateButton",
                        label = "Update"),
           actionButton(inputId = "reset_button",
                        label = "Reset")

#conditional panels

conditionalPanel(
  condition = ("input.updateButton == 0"),
h3("Instructions for calculator"),
),
conditionalPanel(
  condition = "input.updateButton != 0",
  tabPanel(
    "Summary",
      h3("Outputs calculated based on user inputs"),
        )

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.

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