我现在使用rhandsontable函数创建了一个表,如何更新提交按钮上的表?

时间:2016-11-17 05:22:54

标签: r shiny rhandsontable

ui <- fluidPage(

  # Application title
 # titlePanel("Old Faithful Geyser Data"),

    mainPanel(
     rHandsontableOutput('table'),
     br(),
     submitButton("Apply changes"),
     verbatimTextOutput('selected')
     )

)

 server <-  function(input, output) {
      data1 = read.csv("SampleCSVFile_2kb.csv", TRUE,",")


      output$table = renderRHandsontable(rhandsontable(data1, width = 1000, height = 250))

      output$selected=renderPrint({
        cat('\nChanged Cell Old Value:',input$table$changes$changes[[1]][[3]])
        cat('\nChanged Cell New Value:',input$table$changes$changes[[1]][[4]])
      })
    }

shinyApp(ui = ui, server = server)

1 个答案:

答案 0 :(得分:1)

根据我的理解,当您按下提交按钮时,您希望访问服务器内rhandsontable的输入。 在下面的示例中,我修改了您的代码,以便在tableoutput中显示更新的rhandsontable。

library(shiny)
library(rhandsontable)

ui <- fluidPage(

  # Application title # titlePanel("Old Faithful Geyser Data"),

  mainPanel(
    rHandsontableOutput('table'),
    br(),
    submitButton("Apply changes"),
    verbatimTextOutput('selected'),
    ##The updated table output
    rHandsontableOutput('tableoutput')
  )
) 


server <- function(input, output) {
  data1 = read.csv("SampleCSVFile_2kb.csv", TRUE,",")


  output$table = renderRHandsontable(rhandsontable(data1, width = 1000, height = 250))

  output$selected=renderPrint({
    cat('\nChanged Cell Old Value:',input$table$changes$changes[[1]][[3]])
    cat('\nChanged Cell New Value:',input$table$changes$changes[[1]][[4]])
  })

   observe(
     if(!is.null(input$table)){
       output$tableoutput = renderRHandsontable(rhandsontable(hot_to_r(input$table), width = 1000, height = 250))


     }
   )

}


shinyApp(ui = ui, server = server)

希望它有所帮助!