R闪亮:如何捕捉特定目录中的更改



我有一个shinyApp,我想在其中捕获特定目录中的更改。

即:用户点击shinyDirButton,在特定目录中创建一个子目录。我想捕捉这个目录中的任何更改(创建、删除(。我尝试使用reactiveValues,但没有成功

library(shiny)
ui = fluidPage(sidebarLayout(
sidebarPanel(
class = "sidebar_upload",
id = "form",


tags$h1("1- Choose a folder"),
shinyFiles::shinyDirButton(
id = 'choose_directory',
label = 'Choose a folder',
title = 'Choose a folder',
multiple = F
),
br(),
br(),
br(),
actionButton("button", "Update")

),

mainPanel(uiOutput(outputId = "test"))
))

server <- function(input, output, session) {
r_global <- reactiveValues()

observe({
r_global$volumes = c(home = 'C:/')
r_global$dossier = list.dirs(r_global$volumes,
recursive = F,
full.names = F)



shinyFiles::shinyDirChoose(
input = input,
id = 'choose_directory',
roots = r_global$volumes,
session = session
)
})

observeEvent(input$button, {
print(r_global$dossier)
})
}
shinyApp(ui, server)

您必须用observeEvent替换您的第一个观察:

library(shiny)
ui = fluidPage(sidebarLayout(
sidebarPanel(
class = "sidebar_upload",
id = "form",


tags$h1("1- Choose a folder"),
shinyFiles::shinyDirButton(
id = 'choose_directory',
label = 'Choose a folder',
title = 'Choose a folder',
multiple = F
),
br(),
br(),
br(),
actionButton("button", "Update")

),

mainPanel(uiOutput(outputId = "test"))
))

server <- function(input, output, session) {
r_global <- reactiveValues()
#############################  
### here add observeEvent ###
#############################
observeEvent(input$button, {
r_global$volumes = c(home = '~/project/SHINY/wedding/PROJET/')
r_global$dossier = list.dirs(r_global$volumes,
recursive = F,
full.names = F)



shinyFiles::shinyDirChoose(
input = input,
id = 'choose_directory',
roots = r_global$volumes,
session = session
)
})

observeEvent(input$button, {
print(r_global$dossier)
})
}
shinyApp(ui, server)

相关内容

  • 没有找到相关文章

最新更新