-1

I'm trying to create a conditional panel in Shiny based on the length of an input (character string) vector. Specifically, I have a fileInput widget (e.g. Id = FILEWIDGET), and I want to render a conditional panel only if the number of uploaded files is <= 1. I don't speak javascript, but the conditional written in R would look like:

conditionalPanel(condition = input$FILEWIDGET$name <= 1 , ...)

Hopefully this is a straightforward question for those familiar with JS. Thanks in advance.

1 Answer 1

0

I found an expression to put in the conditionalPanel to make it work.

runApp(shinyApp(
  ui = fluidPage(
    fileInput("files","sdfsd", multiple = TRUE),
    conditionalPanel("$('#files')[0].files.length <= 1", p("<= 1 files selected"))
  ),
  server = function(input, output, session) {
  }
))

However, it's a little awkward because it doesn't use the usual shiny condition format of "input.files...", and instead I'm using jQuery for the condition. I don't know if the Shiny devs will say this is fine or if they'll say it's bad. Files are handled in a weird way in Shiny and using input.files.files.length doesn't seem to work, that's why I had to revert to jQuery

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.