【发布时间】:2021-01-02 18:56:02
【问题描述】:
我有一个闪亮的应用程序,它带有一个允许列排序的 DT 表。替换数据时,我还想删除用户可能单击的任何列排序。但是,当数据被替换时,它会自动根据表中指定的排序进行排序。我看不到任何将排序重置为replaceData 函数的一部分或作为独立代理函数的选项。是否可以在不重新渲染表格的情况下做到这一点?
library(DT)
library(shiny)
ui <- fluidPage(
DTOutput(outputId = "table"),
actionButton(inputId = "replace", label = "Replace Data")
)
server <- function(input, output) {
output$table <- renderDT({
datatable(data = data.frame(COL_1 = c(1, 3, 2)), rownames = FALSE)
})
observeEvent(input$replace, {
data <- data.frame(COL_1 = c(4, 6, 5))
replaceData(proxy = dataTableProxy(outputId = "table"),
data = data,
rownames = FALSE)
})
}
shinyApp(ui = ui, server = server)
【问题讨论】: