【问题标题】:how can I dynamically update datatable in shiny app? [r]如何在闪亮的应用程序中动态更新数据表? [r]
【发布时间】:2020-07-28 12:03:32
【问题描述】:

我想用 actionButton 清除数据表。 该块确实有效,但表仍然存在。按下 actionButton 时如何更新表格的内容? 请找到以下玩具样品。

library(shiny)
library(shinydashboard)
library(DT)

    DT1 <- iris
  shinyApp(  
    ui <- 
      dashboardPage(
        dashboardHeader(title = ""),
        dashboardSidebar(),
        dashboardBody(
          DTOutput("DT"),
          actionButton("clear", "clear")
        )
      ),

    server <- 
      function(input, output, session) {
        output$DT <- renderDT(datatable(DT1))
        observeEvent(input$clear, {
          DT1 <- data.frame()
        })
      }
  )

【问题讨论】:

    标签: r shiny


    【解决方案1】:

    这就是你需要的 -

    server <- function(input, output, session) {
        
      dt_data <- reactiveValues(dt_data = iris)
      
      observeEvent(input$clear, {
        dt_data$dt_data <- data.frame() # use iris[0, ] if you want empty df
      })
      
      output$DT <- renderDT(datatable(dt_data$dt_data))
    }
    

    【讨论】:

    • 谢谢,你说得对。答案太明显了,我瞎了。
    猜你喜欢
    • 2015-01-15
    • 1970-01-01
    • 2014-04-11
    • 2017-12-05
    • 2020-04-22
    • 1970-01-01
    • 1970-01-01
    • 2014-01-08
    • 2013-01-31
    相关资源
    最近更新 更多