【发布时间】:2016-04-28 02:48:42
【问题描述】:
我想在开始时存在数据框时扩展此应用程序。老实说,我的问题比这更大,您可以在以下链接中找到问题:How to add a new row to uploaded datatable in shiny
通过这个问题,我将与未成年人一起追逐大局。 我有一个当前的数据框,2 列和 3 行。第一列表示当前日期,另一列需要计算。新行应显示为(当前日期 - 像 Excel 中一样,例如 11.02.2015-, [Input$1 + "perivious value of column2's row"])
但是,我在显示系统日期时遇到了问题。另外,我无法生成在 newLine 中发出警告的新行!
第二个版本:可以上传数据。错误:read.table 中的错误(文件 = 文件,标题 = 标题,sep = sep,quote = quote,: 'file' 必须是字符串或连接 警告:观察者中未处理的错误:“闭包”类型的对象不是子集 观察事件(输入$更新)
library(shiny)
library(gtools)
runApp(
list(
ui = fluidPage(
pageWithSidebar(
headerPanel("Adding entries to table"),
sidebarPanel(
wellPanel(fileInput('file1', 'Choose Planning File:', accept=c('text/csv', 'text/comma-separated-values,text/plain', '.csv'), multiple = FALSE),
selectInput(inputId = "location",label = "Choose Location",
choices = c('All','Lobau'='LOB', 'Graz'='GRA', 'St. Valentin'='VAL'), selected = "GRA"),
selectInput(inputId = "product",label = "Choose Product",
choices = c('All','Gasoline'='OK', 'Diesel'='DK'), selected = "DK")),
numericInput("spotQuantity", "Enter the Spot Quantity",value=0),
actionButton("action","Confirm Spot Sales"),
numericInput("num2", "Column 2", value = 0),
actionButton("update", "Update Table")),
mainPanel(tableOutput("table1")))
),
server = function(input, output, session) {
values <- reactive({ #
#file.choose()
dm <- as.data.frame(read.csv(input$file1$datapath, sep=";",check.names = FALSE))
})
addData <- observeEvent(input$update, {
values$dm <- isolate({
newLine <- data.frame('Month'=1,'Day ID'=2,'Day'="28-11-2012",'starting inventory'=2,'planned (in kTO)'=2,'lifted (in kTO)'="2",'replenishment (in kTO)'="2", 'Product'="OK",'Location'="GRA", check.names=F)
rbind.data.frame(values$dm,newLine)
})
})
output$table1 <- renderTable({
values()
})
}
) )
【问题讨论】:
-
试试
rhandsontable包。