鉴于您提供的代码,我无法具体重现您的代码,但也许一个示例会对您有所帮助。你需要的部分是reactiveValues
,这允许您存储数据集并在整个会话期间根据您认为合适的情况进行更新。也许这可以帮助您解决问题?
require(shiny)
data(iris)
runApp(
list(
ui = fluidPage(
headerPanel('Adding Data'),
sidebarPanel(
textInput("species", label="Add a new species", value="Enter species"),
numericInput("sepal.length", label="Add a new sepal length", value=""),
numericInput("sepal.width", label="Add a new speal width", value=""),
numericInput("petal.length", label="Add a new petal length", value=""),
numericInput("petal.width", label="Add a new petal width", value=""),
actionButton("addButton", "UPLOAD!")
),
mainPanel(
tableOutput("table"))
),
server = function(input, output) {
# just a small part of iris for display
iris_sample <- iris[sample(nrow(iris), 10),]
row.names(iris_sample) <- NULL
# The important part of reactiveValues()
values <- reactiveValues()
values$df <- iris_sample
observe({
# your action button condition
if(input$addButton > 0) {
# create the new line to be added from your inputs
newLine <- isolate(c(input$sepal.length, input$sepal.width, input$petal.length, input$petal.width, input$species))
# update your data
# note the unlist of newLine, this prevents a bothersome warning message that the rbind will return regarding rownames because of using isolate.
isolate(values$df <- rbind(as.matrix(values$df), unlist(newLine)))
}
})
output$table <- renderTable({values$df}, include.rownames=F)
}
)
)