【发布时间】:2023-01-13 00:30:02
【问题描述】:
我有一个应用程序,我需要在其中监视文件的更改。但是我正在努力做到这一点。
考虑以下示例:
library(shiny)
返回文件修改日期的函数:
file_info <- function(){
if(file.exists("example.txt")){
return(as.character(as.Date(file.info("example.txt")[1,4])))
} else {
return("File not present")
}
}
闪亮部分:
ui <- shinyUI(fluidPage(
textOutput("file_status"),
actionButton("create_file", "Create file"),
actionButton("delete_file", "Delete file")
))
server <- shinyServer(function(input, output, session) {
file_st <- reactive(file_info()) #what is the correct approach here?
output$file_status <- renderText({
file_st()
})
observeEvent(input$create_file,{
file.create("example.txt")
})
observeEvent(input$delete_file, {
unlink("example.txt")
})
})
我希望 file_status 文本字段在每次 example.txt 文件更改时更新 - 如果可能,即使这发生在应用程序之外。
我尝试了 reactive、observe 和 reactiveValues 的各种组合,但没有找到合适的组合。
谢谢
【问题讨论】: