【问题标题】:Get edited cells from R ShinyTable to update dataFrame从 R ShinyTable 获取已编辑的单元格以更新 dataFrame
【发布时间】:2016-06-20 16:58:15
【问题描述】:

我有一个在 R ShinyTable 中渲染的 R 数据框。 ShinyTable 中的编辑工作正常。

我的问题是:如何获取用户所做的编辑并更新我的数据框。

以下代码取自 ShinyTable 的教程网站。它有一个错误:“尝试访问已弃用的 Shinysession$session 对象。请直接访问 Shinysession 对象。”但是代码中没有任何内容引用shinySession。

如果我能在回答我的主要问题(如何接受用户所做的编辑)方面获得帮助,我可以绕过这个错误。

 library(shiny)
 library(shinyTable)
server <- function(input, output, session) {
  rv <- reactiveValues(cachedTbl = NULL)
  output$tbl <- renderHtable({
    if (is.null(input$tbl)){
      tbl <- matrix(0, nrow=3, ncol=3)
      rv$cachedTbl <<- tbl
      return(tbl)
    } else{
      rv$cachedTbl <<- input$tbl
      return(input$tbl)
    }
  })  

  output$tblNonEdit <- renderTable({
    input$actionButtonID
    isolate({
      rv$cachedTbl
    })
  })    
}
ui <- shinyUI(pageWithSidebar(
  headerPanel("shinyTable with actionButton to apply changes"),
  sidebarPanel(
    helpText(HTML("
                  Make changes to the upper table, press the button to activate. 
                  <p>Created using <a href = \"http://github.com/trestletech/shinyTable\">shinyTable</a>."))),
  mainPanel(
    htable("tbl"),
    actionButton("actionButtonID","apply edits"),
    tableOutput("tblNonEdit")
  )
))

shinyApp(ui = ui, server = server)

【问题讨论】:

    标签: r shiny reactive-programming handsontable


    【解决方案1】:

    shinyTable 好像有几年没有更新了。会话错误发生在包代码中,而不是您的代码中。

    改用 rhandsontable。

    我通过一些有效的示例代码找到了这个问题/答案: Update handsontable by editing table and/or eventReactive

    library(shiny)
    library(rhandsontable)
    
    did_recalc <- FALSE
    
    ui <- fluidPage(
      rHandsontableOutput('table'),
      textOutput('result'),
      actionButton("recalc", "generate new random vals and calculate")
    )
    
    server <- function(input,output,session)({
      values <- reactiveValues(data=as.data.frame(runif(2)))
    
      observe({
        input$recalc
        values$data <- as.data.frame(runif(2))
      })
    
      observe({
        if(!is.null(input$table))
          values$data <- hot_to_r(input$table)
      })
    
    
      output$table <- renderRHandsontable({
        rhandsontable(values$data)
      })
    
    
      output$result <- renderText({ 
        sum(values$data)
      })
    })  
    
    shinyApp(ui = ui, server = server)
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-03-29
      • 1970-01-01
      • 1970-01-01
      • 2016-03-14
      • 1970-01-01
      • 2012-06-27
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多