3

在闪亮的情况下,我将如何更新 DT 表中的值而不重新绘制整个表并因此在每次更新时闪烁。

以下示例将标准 tableOutput 与 DT::dataTableOutput 进行比较。请注意每次更新 dataTableOutput 时的闪烁。有没有办法避免这种情况并有更流畅的用户交互?ui.R 和 server.R 示例如下。

require(shiny);require(DT)
shinyUI(fluidPage(
  titlePanel("Sliders"),

  sidebarLayout(
    sidebarPanel(
      sliderInput(
        "integer", "Integer:",
        min = 0, max = 1000, value = 500
      ),

      sliderInput(
        "decimal", "Decimal:",
        min = 0, max = 1, value = 0.5, step = 0.1
      ),

      sliderInput(
        "range", "Range:",
        min = 1, max = 1000, value = c(200,500)
      ),

      sliderInput(
        "format", "Custom Format:",
        min = 0, max = 10000, value = 0, step = 2500,
        pre = "$", sep = ",", animate = TRUE
      ),

      sliderInput(
        "animation", "Looping Animation:", 1, 2000, 1,
        step = 10, animate =
          animationOptions(
            interval = 300, loop = TRUE,
            playButton = "PLAY", pauseButton = "PAUSE"
          )
      )
    ),

    mainPanel(tableOutput("values"),
              DT::dataTableOutput('DTtable'))
  )
))


shinyServer(function(input, output) {
  sliderValues <- reactive({
    data.frame(
      Name = c("Integer",
               "Decimal",
               "Range",
               "Custom Format",
               "Animation"),
      Value = as.character(
        c(
          input$integer,
          input$decimal,
          paste(input$range, collapse = ' '),
          input$format,
          input$animation
        )
      ),
      stringsAsFactors = FALSE
    )
  })

  output$values <- renderTable({
    sliderValues()
  })
  output$DTtable = DT::renderDataTable(rownames = FALSE,
                                       {
                                         sliderValues()
                                       },
                                       options = list(processing = FALSE))
})

看起来理想的解决方案是实现重新加载功能: https://datatables.net/reference/api/ajax.reload()

关于如何做到这一点的任何建议?

4

0 回答 0