你好我正在用几个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'来检查数据是否发生了变化。 –