0

I have an R dataframe that I am rendering in R ShinyTable. The editing in the ShinyTable works fine.

My question is: how do I take the edits the user has made and update my dataframe.

The code below was taken from a tutorial site for ShinyTable. It has an error: "Attempted to access deprecated shinysession$session object. Please just access the shinysession object directly." But there is nothing in the code that refers to shinySession.

If I can get help answering my primary question (how to take the edits the user has made) I can get around this error.

 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)
PaeneInsula
  • 2,010
  • 3
  • 31
  • 57

1 Answers1

0

It looks like shinyTable hasn't been updated for a few years. The session error is occurring in the package code, not your code.

Try rhandsontable instead.

I found this question/answer with some sample code that works: 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)
Community
  • 1
  • 1
data_modeler
  • 86
  • 1
  • 6