Directory input not working after insertUI - RShiny

shiny

#1

I implement an RShiny app where the user has to click a button (extract_btn). After this happens, an HTML page is created dynamically. And here comes the problem. When I insert a shinyDirButton with insertUI, the directories don’t show up. While inspecting the site the konsole show up this problem:

Code:


#ui.R

library(shiny)
library(shinyFiles)

ui <- shinyUI( fluidPage( theme = "bootstrap.css", 
                          
                          fluidRow(id="first_view", style="display:;",
                                   
                                   tags$a(class="deg225",id="extract_btn",
                                          actionButton(
                                            inputId = "extract_btn", label = HTML("<b>Extract</b>"),
                                            class = " action_button img-circle")
                                   )
                          ),
                          
                          shinyDirButton(id = "dir", label = "Choose directory", "Select PDF-File")
                          
)
)

#server.ui

server <- function(input, output, session) {
  current <- reactiveValues(page="first_view")
  
  #Extract
  observeEvent(input$extract_btn, {
    insertUI(
      selector = paste("#", current$page,sep = ""),
      where = "afterEnd",
      ui = Render_ExtractPage()
    )
    removeUI(selector = paste("#", current$page,sep = ""))
    current$page <- "extract_view"
  })
  # dir
  roots <- getVolumes()  
  shinyDirChoose(input, id = "dir", roots = roots,filetypes = c('', 'pdf'), session=session)
  
  dir <- reactive(input$dir)
  
  
  # path
  path <- reactive({
    file.path(paste(unlist(dir()$path[-1]), collapse = .Platform$file.sep))
  })
  
  Render_ExtractPage <- function() {
    shinyDirButton(id = "dir", label = "Choose directory", "Select PDF-File")   
  }
}

shinyApp(ui = ui, server = server)

I would be very grateful for any help.


#2

Hi @Livruen,
This might be better suited to the #shiny channel! I can’t move posts (i’m not an admin), but you can move it (since it’s yours).

Here’s an excellent illustrated explanation how from the Discourse site


#3

Thank you ! I will do that :slight_smile: