【问题标题】:Update values in editable table in Shiny在 Shiny 中更新可编辑表中的值
【发布时间】:2020-09-14 22:55:25
【问题描述】:

我想更新在 Shiny App 中编辑的表格。我不知道为什么在下面的代码中 mean()observeEvent() 中可以正常工作,但在 output$tekst 中无法自行更新。

library(shiny)
library(DT)

ui <- fluidPage(
    textOutput('tekst'),
    DTOutput('tabela')
)
server <- function(input, output) {
    A <- data.frame("a" = c(1,2,6,5,NA,1), "b" = c(2,2,NA,5,7,NA))
    output$tabela = renderDT(A
                        , selection = 'none'
                        , editable = 'column')
    observeEvent(input$tabela_cell_edit, {
        A <<- editData(A, input$tabela_cell_edit, 'tabela')
        cat(mean(A$a, na.rm = TRUE), "\n\n")
    })
    output$tekst <- renderText({mean(A$a, na.rm = TRUE)})
}
shinyApp(ui = ui, server = server)

帮助:)

【问题讨论】:

    标签: r shiny dt


    【解决方案1】:

    使用响应式值:

    library(shiny)
    library(DT)
    
    ui <- fluidPage(
      textOutput('tekst'),
      DTOutput('tabela')
    )
    server <- function(input, output) {
      A <- data.frame("a" = c(1,2,6,5,NA,1), "b" = c(2,2,NA,5,7,NA))
      reactA <- reactiveVal(A)
      output$tabela = renderDT(A
                               , selection = 'none'
                               , editable = 'column')
      observeEvent(input$tabela_cell_edit, {
        reactA(editData(reactA(), input$tabela_cell_edit, 'tabela'))
      })
      output$tekst <- renderText({mean(reactA()$a, na.rm = TRUE)})
    }
    shinyApp(ui = ui, server = server)
    

    【讨论】:

      猜你喜欢
      • 2018-11-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-06-09
      • 1970-01-01
      • 2019-11-26
      • 2020-10-21
      • 2021-03-07
      相关资源
      最近更新 更多