有光泽:在另一个renderRHandsontable({})表达式中使用renderRHandsontable({})中生成的数据

时间:2016-10-17 08:17:29

标签: r shiny data-manipulation rhandsontable reactive

下面是我想要实现的模式      data< - read.csv(" data.csv")

 output$table1 <- renderRHandsontable({
 data <- data*2
 data_table <- filter(data, "ID1")
 rhandsontable(data_table)})

 output$table2 <- renderRHandsontable({rhandsontable(data)})

我想阅读一些数据,在rhandsontable中操纵(代价高昂)并在另一个rhandsontable中使用日期。每当我更新table1中的数据时,表2也应该更新。有人可以帮我吗?

1 个答案:

答案 0 :(得分:1)

我认为以下代码可以满足您的需求。这里只有在第一个表中进行一些更改后才会呈现第二个表。

ui.R如下:

library(shiny)
library(rhandsontable)

ui <- fluidPage(
  rHandsontableOutput("Table1"),
  br(),
  br(),
  rHandsontableOutput("Table2")
)

服务器。 R如下:

server <- function(input, output, session) {

  #Render !st table at the begining 
  output$Table1 <- renderRHandsontable({

    rhandsontable(datasets::mtcars, height = 400, selectCallback = TRUE, readOnly = FALSE)
  })


  observe({
    if(!is.null(input$Table1$changes$changes[[1]][[1]])){# Render the 2nd table only after the data in the 1st table changes

      output$Table2 <- renderRHandsontable({

        rhandsontable(hot_to_r(input$Table1), height = 400, readOnly = TRUE)

      }) 
    }

  })

}

希望这有帮助!