简体   繁体   English

在 shiny 中编辑 rhandsontable

[英]Edit rhandsontable in shiny

I trying to update my rhansontable based on values from a and b.我试图根据 a 和 b 的值更新我的 rhansontable。 But its not getting updated.但它没有得到更新。 Basially, column c should be column a divided column b基本上,列 c 应该是列 a 分列 b

library(shiny)
library(rhandsontable)

did_recalc <- FALSE

ui <- fluidPage(
  # tableOutput(table1),
  rHandsontableOutput('table'),
  textOutput('result')
)

server <- function(input,output,session)({
  # values <- reactiveValues(data=as.data.frame(runif(2)))
  INR = c(0)
  `Price` = c(0)
  Total = as.numeric(INR / `Price`)
  
  values <- data.frame(a = INR, b = `Price`, c = Total)
  
  observe({
    if(!is.null(input$table))
      values <- hot_to_r(input$table)
  })
  
  
  
  output$table <- renderRHandsontable({
    rhandsontable(values)
  })
  
}) 

shinyApp(ui = ui, server = server)

You need to make sure that the object holding the data ( values ) is reactive.您需要确保保存数据( values )的 object 是反应性的。 This will force anything using it to update properly.这将强制使用它的任何东西正确更新。

library(shiny)
library(rhandsontable)
library(dplyr)

ui <- fluidPage(
    rHandsontableOutput('table')
)

server <- function(input,output,session)({
    
    values <- reactiveVal(value = data.frame(INR = runif(2), 
                                             Price = runif(2)))
    
    output$table <- renderRHandsontable({
        values() %>% 
            mutate(Total = INR/Price) %>% 
            rhandsontable() %>% 
            hot_col("Total", readOnly = TRUE)
    })
    
    observe({
        if(!is.null(input$table))
            values(hot_to_r(input$table))
    })
    
}) 

shinyApp(ui = ui, server = server)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM