我正在尝试使用以下功能构建R闪亮:
以下是我的代码。如果我选择表radiobutton,并使用值更新表并点击保存,它会给我错误消息。错误消息表明我调用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
谢谢, Krina
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)
Server.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})
})
答案 0 :(得分:1)
这似乎是一个已知的问题,可以通过CRAN使用旧版本的rhandsontable。
解决方案是从github安装rhandsontable包。
devtools::install_github("jrowen/rhandsontable", dependencies = T, upgrade_dependencies = T)