r 闪亮:更新来自数据库中搜索的 rhandsontable 默认输入

问题描述

我正在尝试使用认的 rhandsontable 表创建一个闪亮的应用程序,然后用户有两个选项来更新它:

  1. 直接在 rhandsontable 表上手动完成或
  2. 使用数字输入和 actionButton数据库搜索数据

我的代码在这里

library(shiny)
library(rhandsontable)
library(data.table)

data_pop <- data.table(`Number` = c(1,1,2,3,3),`Country` = c("Andorra","Angola","Anguilla","Antigua and Barbuda","Argentina","Armenia"),`Population` = c(123,456,789,246,369,159))

ui <- navbarPage(title = tags$b(tags$span("APP")),id = "nav",fluid = TRUE,tabPanel(tags$b(tags$span("Model")),sidebarLayout(
                            sidebarPanel( 
                              numericInput("number",label = "Number",value = 0,min = 0,max = Inf),actionButton("load","Load",align = 'right'),),mainPanel(
                              rHandsontableOutput("out_table"),)
                          )
                 )
)

server <- function(input,output) {
  
  default <- data.table(`Country` = "",`Column` = as.integer(0),stringsAsFactors = FALSE)

  values <- reactiveValues()

  observe({
    
    if (!is.null(input$table)) {
      table <- hot_to_r(input$out_table_country)
    } else {
      if (is.null(values[["table"]])) {
        
        default <- eventReactive(input$load,{
          data_pop[`Number` == input$number,.(`Country`,`Population`)]
        })
        table <- default
      }
      else {
        table <- values[["table"]]
      }
    }
    values[["table"]] <- table
  })
  
  output$out_table <- renderRHandsontable({
    table <- values[["table"]]
    if (!is.null(table))
      rhandsontable(table,stretchH = "all") %>%
      hot_col(col = "Country",type = "autocomplete",source = data_pop$Country,strict = T) %>%
      hot_col(col = "Column",format = "0,0") 
  })
}

shinyApp(ui = ui,server = server)

当我尝试用响应式表替换 default 表时出现问题,我得到:

Error in as.vector: cannot coerce type 'closure' to vector of type 'list'

我不知道它是否与列上的 hot_col 格式有关... 我已经尝试了很多解决方案,但都没有奏效,非常感谢您的帮助!

非常感谢,

费边

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)