【发布时间】:2015-11-02 14:42:59
【问题描述】:
您好,我正在使用几个 excel 文件构建一个闪亮的仪表板。
我在框的页脚中插入了指向这些文件的链接,并且我想在我的 excel 文件中更改某些内容时刷新闪亮仪表板。 我不想每次都运行整个 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以检查数据是否已更改。
标签: r shinydashboard