你好我正在用幾個excel文件構建一個shinydashboard。如何更新文件更改的用戶界面
我在框的頁腳中插入了這些文件的鏈接,並且想要在更改excel文件中的某些內容時更新 shinydashboard的。 我不想每次都運行整個R代碼。
一旦文件內容發生變化,我該如何重新渲染輸出?
下面的例子:
sidebar <- dashboardSidebar(
sidebarMenu(menuItem("Hello", tabName = "Hello", icon = icon("dashboard"))
))
body <- dashboardBody(
tabItems(
tabItem(tabName = "Hello",
box(title = "my file",
footer = a("df.xlsx", href="df.xlsx") ,
DT::dataTableOutput("df1"),style = "font-size: 100%; overflow: auto;",
width = 12, hight = NULL, solidHeader = TRUE, collapsible = TRUE, collapsed = TRUE, status = "primary")
)))
ui <- dashboardPage(
dashboardHeader(title = "My Dashboard"),
sidebar,
body)
server <- function(input, output) {
output$df1 <- renderDataTable({
df <- read_excel("df.xlsx")
DT::datatable(df, escape = FALSE, rownames=FALSE,class = "cell-border",
options =list(bSort = FALSE, paging = FALSE, info = FALSE)
)
})
}
shinyApp(ui, server)
你可以用tools :: md5sum來計算md5,當這個文件改變時你可以更新你的UI。看看'tcltk2 :: tclTaskSchedule'在計時器上運行任務,或者'invalidateLater'來檢查數據是否發生了變化。 –