我想在闪亮的App中制作一个格式化的表,用户可以在其中选择行,然后在需要时刷新表。重新加载整个表是一个麻烦的策略。我找到了一个技巧,如何刷新数据表,但似乎不适用于数据表对象。有办法吗?
下面是问题的示例。预先感谢您的任何输入:)
library(shiny)
library(DT)
shinyApp(
ui = fluidPage(
fluidRow(
column(2, actionButton('refresh', 'Refresh Data', icon = icon('refresh'))),
column(10, DT::dataTableOutput('foo'))
)
),
server = function(input, output, session) {
df <- iris
n <- nrow(df)
df$ID <- seq_len(n)
loopData <- reactive({
input$refresh
df$ID <<- c(df$ID[n], df$ID[-n])
df <- DT::datatable(df,
selection = "multiple",
rownames = FALSE,
style = "bootstrap",
class = 'table-bordered table-condensed',
filter = list(position = "top"),
extensions = c('Buttons', 'Responsive'),
# ,'Scroller'),
options = list(
dom = 'Bfrtip',
buttons = c('copy', 'csv', 'excel', 'pdf', 'print', I('colvis')),
orderClasses = TRUE,
searchHighlight = TRUE,
lengthMenu = c(5, 30, 50),
pageLength = 6))
df
})
output$foo <- DT::renderDataTable(isolate(loopData()))
proxy <- dataTableProxy('foo')
observe({
replaceData(proxy, loopData(), resetPaging = FALSE)
})
}
)