【问题标题】:rhandsontable update in R Shiny AppR Shiny App 中的 rhandsontable 更新
【发布时间】:2018-04-28 01:54:35
【问题描述】:

我正在尝试使用以下功能构建一个闪亮的 R:

  • 用户有两个选项来输入他们需要在应用程序中进一步处理的数据,上传 csv 文件或在应用程序中填写表格。
  • 我可以正常上传 csv 文件。问题在于表格部分。当用户选择输入表格时,会出现一个 2 列 x 10 行的表格。用户更新并保存表格后,应将表格转换为数据框以进行进一步处理。

以下是我目前的代码。如果我选择表格单选按钮,并使用值更新表格并点击保存,它会给我错误消息。错误消息表明我调用 hot_to_r() 函数存在一些问题。以下是完整的错误信息:

Warning: Error in row.names<-.data.frame: invalid 'row.names' length
Stack trace (innermost first):
    71: row.names<-.data.frame
    70: row.names<-
    69: rownames<-
    68: <Anonymous>
    67: do.call
    66: hot_to_r
    65: observeEventHandler [C:\Users\kmehta\Documents\Projects\Enhanze\Test/server.R#46]
     1: runApp

谢谢, 克里纳

ui.R

library(shiny)
library(shinydashboard)
library(shinyBS)
library(dplyr)
library(gdata)
library(rhandsontable)

#Design sidebar
sidebar <- dashboardSidebar(width = 200, collapsed=F, 
                            sidebarMenu(id="tabs",
                                        menuItem("TEST", tabName = "thick", icon = icon("puzzle-piece"))))

#Design body 
body <- dashboardBody(
  tabItems(
    tabItem(tabName = "thick", 
            box(collapsible=TRUE, width = 4, status = "success", solidHeader = T, title="Input",
                radioButtons(inputId="fileInput", "Choose data input method", choices = c("csv", "table"), selected = 'csv'),  
                conditionalPanel(condition = "input.fileInput == 'csv'", 
                                 fileInput(inputId="file", label = "Upload data in CSV file", accept = c(".csv"))),
                conditionalPanel(condition="input.fileInput == 'table'",
                                 rHandsontableOutput("hot"),
                                 actionButton("save", "Save table")),
                numericInput('Dose', 'mAB dose (mg)', value=0, min=0),
                actionButton('gothick','Run', class='btn btn-info', icon=icon('play-circle-o','fg-lg'))),
            box(collapsible=T, width=6, status = "success", solidHeader = T, title="Table", tableOutput('Table')))
  ))

#Show title and the page (includes sidebar and body)
dashboardPage(skin="blue",
              dashboardHeader(title = "TEST", 
                              titleWidth = 800),
              sidebar,  body)

服务器.R

library(shiny)
library(shinydashboard)
library(shinyBS)
library(RxODE)
library(ggplot2)
library(dplyr)
library(gdata)
library(rhandsontable)

Concentration <- c(0,0,0,0,0,0,0,0,0,0)
Viscosity <- c(0,0,0,0,0,0,0,0,0,0)
DF <- data.frame(Concentration, Viscosity)

shinyServer(function(input, output, session){

#Handsontable

  output$hot <- renderRHandsontable({
    rhandsontable(DF, useTypes = F)
  })

  observeEvent(input$save, {
    DF1 = hot_to_r(input$hot)
    finalDF <- DF1
    })

  ThickFastFun <- eventReactive(input$gothick, {
    if (!is.null(input$file)) 
    {dat <- read.csv(inFile$datapath, header=T, stringsAsFactors = F)}
    else {dat <- finalDF}
    return(dat)
  })

  #Table
  ThickFast_Table <- reactiveValues(df = NULL)
  observeEvent(input$gothick, {
    ThickFast_Table$df <- ThickFastFun()})

  output$ThickFastTable <- renderTable({ThickFast_Table$df})

})

【问题讨论】:

  • 请包含错误消息的实际文本。
  • 谢谢,我更新了问题以包含错误消息。

标签: r shiny rhandsontable


【解决方案1】:

这似乎是可通过 CRAN 获得的旧版本 rhandsontable 的一个已知问题。

解决方案是从github安装rhandsontable包。

devtools::install_github("jrowen/rhandsontable", dependencies = T, upgrade_dependencies = T)

【讨论】:

    猜你喜欢
    • 2017-12-02
    • 1970-01-01
    • 1970-01-01
    • 2017-04-30
    • 2018-05-18
    • 1970-01-01
    • 2018-02-08
    • 2020-12-15
    • 2020-06-26
    相关资源
    最近更新 更多