0

I want to hide all elements from a shiny app page on it's load if some condition in the server.R is not TRUE. I tried doing it like this:

server.R

output$a <- reactive({
  if (condition) {
    TRUE
  } else {
    FALSE
  }
})
outputOptions(output, 'a', suspendWhenHidden=FALSE)

and then cover everything in ui.R with conditionalPanel("output.a == true", ...). It works, but my problem is that it still loads all the elements that are inside of that conditionalPanel, even if it's in FALSE state. So in <div data-display-if="output.a == true"> there are all the elements i wanted to 'hide' from the user.

Now the question: is it possible to do that kind of conditional behaviour on server-side of an app, and load whole UI if it succeeds? So before I send TRUE in some reactive to the UI, it loads nothing, or some dummy UI that would tell user something is wrong.

vladli
  • 1,454
  • 2
  • 16
  • 40
  • have a look at `shinyjs` and its `show` and `hide` functions – Pork Chop Nov 13 '17 at 14:23
  • It works the same with `shinyjs` for me. It hides the element visually, but it still exists in dev tools – vladli Nov 13 '17 at 14:34
  • 1
    Have a look at my example https://stackoverflow.com/questions/28987622/starting-shiny-app-after-password-input/28997605#28997605 – Pork Chop Nov 13 '17 at 14:53
  • It seems like the thing I needed, though there is a lot of work to do to try it out. I'll use it as a guide and see if it works for me, thanks! – vladli Nov 13 '17 at 14:58
  • The idea there is to generate 2 separate html pages and only show the ones you need – Pork Chop Nov 13 '17 at 14:58
  • @PorkChop maybe you have some time to help me out. I tried to follow your example, and made it work for the `ui1`, which is a 'dummy' end-route page. With `ui2` though it doesn't seem to work so easily. I put in `ui2` my whole `ui.R` contains and in `ui.R` I left `htmlOutput("page")` as per example. The app contained `source()` in the `server.R` before, now I'm trying to make everything work there. I'm putting `source()` in the if statement that loads the `ui2` function, but it doesn't seem to work. I get errors on `if()`'s with `input$...` used inside of it across all files. Any ideas? – vladli Nov 13 '17 at 17:04
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/158881/discussion-between-pork-chop-and-claud-h). – Pork Chop Nov 13 '17 at 17:11

0 Answers0