【问题标题】:Edit rhandsontable in shiny在闪亮中编辑 rhandsontable
【发布时间】:2021-04-30 11:21:39
【问题描述】:

我试图根据 a 和 b 的值更新我的 rhansontable。但它没有得到更新。基本上,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)

【问题讨论】:

    标签: r shiny


    【解决方案1】:

    您需要确保保存数据的对象 (values) 是响应式的。这将强制任何使用它的东西正确更新。

    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)
    

    【讨论】:

    • 谢谢。但是我们只能在单张桌子上做吗?我不需要table1。我只需要一个rhandsontable
    猜你喜欢
    • 2018-06-19
    • 2019-01-29
    • 2017-09-20
    • 2019-10-20
    • 2017-05-11
    • 2019-08-01
    • 2017-01-30
    • 2015-05-22
    • 2016-09-23
    相关资源
    最近更新 更多