Commissar Vasili Karlovic Commissar Vasili Karlovic - 2 months ago 10
R Question

Is shiny able to use interactive ui?

I'm almost done with my project and I'm trying to do some aesthetic changes to my app in order to be more user friendly and attractive.

The idea:
Since my app requires to upload a table in order to work, I thought it would be better if I put a stand alone large upload button in the middle of the screen and then a navigation bar would appear with the results, plots, downloads would appear.

Here's what I've tried:

shinyUI(

fileInput("file","Upload the file")

if(!is.null(input$file)) {
navbarPage("My Application",
tabPanel("Data", tableOutput("table")),
tabPanel("Summary", tableOutput("sum")),
tabPanel("Regression", verbatimTextOutput("reg")),
tabPanel("Wavelet Coefficients", htmlOutput("tmod1"),
tableOutput("mod1"),
tableOutput("mod2")),
tabPanel("Wavelet Plot", plotOutput("plot")),
tabPanel("About file", tableOutput("filedf"))
)}
)


The error is the following:

ERROR: D:\OneDrive\MODWT App/ui.R:7:1: unexpected 'if'
6:
7: if
^


Is there any solution to this? :/

My current "plan b" is to create two apps, where the first is the upload one, and if the user upload the file then server.R will call the "original" app. Is this even possible?

I apologise if this question seems silly but I'm a noob coder, so I'm not aware of the limitations.

Thanks

Answer

To dynamically add or remove UI elements in Shiny you should use the built-in dynamic UI functions such as conditionalPanel.

You'll move the logic from your if statement to the condition argument of conditionalPanel.

There are a few other functions like that which you can read about here and you can also use custom JS.

Comments