So I'm trying to make a shiny app where I have a button which only shows up if files have been uploaded; for this im using conditionalPanel.
ui.R:
require(shiny)
shinyUI(pageWithSidebar(
headerPanel("My App"),
sidebarPanel(
fileInput("files", "Choose file"),
conditionalPanel(
condition = "input.files",
actionButton("submitFiles", "Submit files for processing"))),
mainPanel(h3("Nothing to see here"))
))
I don't think there's anything to care about in my server.R, since the above example doesn't do anything. With the above condition, the button never shows up, i.e. the condition is never true.
Some things I've tried for my condition are input.files.length > 0
, input.files.size() > 0
, both of which result in the button being present before I upload a file. I'm guessing this is because input$files is an empty data.frame before choosing files, and so has a non-zero length/size, is that right?
What condition can I use to hide the button until at least one file is done uploading?
I think another option would be to replace conditionalPanel
with uiOutput
, and call renderUI({actionButton(...)})
inside of an observe/isolate block in server.R which is watching input.files (if (nrow(input$files) < 1) return()
); is that the only way? If I can do this either way, what would make me pick one or the other (beyond conditionalPanel
resulting in less code)?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…