Shinyfiles and renderUI are not working properly

I am trying to use the shinyFiles library in my shinyApp to give the user the option to select a group of files or a directory. My idea is to use uiOutput, which varies depending on the checkbox selected.

Here I am reporting a code, perhaps more explanatory than words

UtilityUI <- fluidPage(
  titlePanel("page1"),
  fluidRow(
    column(2, 
      wellPanel(
                tags$p("Check the box below if you want to choose an entire directory"),
                checkboxInput(inputId = 'directory_flag', label = 'Directory path?', value = FALSE),
                uiOutput("input_selection_ui")
            )
    ),
    column(8
           #...
           )
  )
)

UtilityServer <- function(input, output, session) {

  output$input_selection_ui <- renderUI({
    if(input$directory_flag == TRUE) {
      shinyDirButton(id = "infiles", label = "Choose directory", title = "Choose a directory")
    } else {
      shinyFilesButton(id = "infiles", label = "Choose file(s)", title = "Choose one or more files", multiple = TRUE)
    }
  })


  shinyFileChoose(input, 'infiles', roots=getVolumes(), session=session, restrictions=system.file(package='base'))
  shinyDirChoose(input, 'infiles', roots=getVolumes(), session=session, restrictions=system.file(package='base'))
}

shinyApp(UtilityUI, UtilityServer)

The problem occurs when the "shinyFiles" button is pressed: the popup does not load the roots in both cases (shinyDirButton and shinyFilesButton).

If I do not use the uiOutput function, everything works fine ... But in this case, I cannot change my UI dynamically ...

Thanks so much for your answers,

Inzirio

+4
source share
1 answer

, renderUI(). , conditionalPanel(), . , . :

ui <- shinyUI(fluidPage(
  checkboxInput(
    inputId = 'directory_flag',
    label = 'Directory path?',
    value = FALSE
  ),

  conditionalPanel(
    "input.directory_flag == 0",
    shinyFilesButton(
      id = "infile",
      label = "Choose file(s)",
      title = "Choose one or more files",
      multiple = TRUE
    )
  ),
  conditionalPanel(
    "input.directory_flag == 1",
    shinyDirButton(id = "indir", label = "Choose directory", title = "Choose a directory")
  )
))

server <- shinyServer(function(input, output, session) {
  shinyFileChoose(
    input,
    'infile',
    roots = getVolumes(),
    session = session,
    restrictions = system.file(package = 'base')
  )
  shinyDirChoose(
    input,
    'indir',
    roots = getVolumes(),
    session = session,
    restrictions = system.file(package = 'base')
  )
})

shinyApp(ui, server)
+1

Source: https://habr.com/ru/post/1616099/


All Articles