Я хотел создать блестящее приложение, которое получает данные от пользователя и сохраняет их в форматах .csv. Но каждый раз, когда пользователь вводит данные, прошлые данные не удаляются, поэтому при добавлении всех предыдущих данных (не обязательно для того же пользователя) добавляются новые введенные данные. Я хотел создать новую «новую» кнопку, которая удаляет прошлые входные данные и дает новую таблицу для ввода.
library(shiny)
ui <- fluidPage(
titlePanel("Creating a database"),
sidebarLayout(
sidebarPanel(
textInput("name", "Company Name"),
textInput("income", "Income"),
textInput("expenditure", "Expenditure"),
dateInput("date", h3("Date input"),value = Sys.Date() ,min = "0000-01-01",
max = Sys.Date(), format = "dd/mm/yy"),
actionButton("Action", "Submit"),#Submit Button
actionButton("new", "New")),
mainPanel(
tableOutput("table"), #Table showing what is there in the data frame
textInput("filename", "Enter Filename for download"), #filename
helpText(strong("Warning: Append if want to update existing data.")),
downloadButton('downloadData', 'Download'), #Button to save the file
downloadButton('Appenddata', 'Append') #Button to update a file
)
)
)
# Define server logic
server <- function(input, output){
#Global variable to save the data
Data <- data.frame()
Results <- reactive(data.frame(input$name, input$income, input$expenditure,
as.character(input$date),
as.character(Sys.Date())))
#To append the row and display in the table when the submit button is clicked
observeEvent(input$Action,{
#Append the row in the dataframe
Data <<- rbind(Data,Results())
#Display the output in the table
output$table <- renderTable(Data)
})
observeEvent(input$new, {
UpdateInputs(CreateDefaultRecord(), session)
})
output$downloadData <- downloadHandler(
# Create the download file name
filename = function() {
paste(input$filename , ".csv", sep="")
},
content = function(file) {
write.csv(Data, file,row.names = FALSE) # put Data() into the download file
})
output$Appenddata <- downloadHandler(
# Append data
filename = function() {
paste(input$filename, ".csv", sep="")
},
content = function(file) {
write.table( Data, file=file.choose(),append = T, sep=',',
row.names = FALSE, col.names = FALSE)
})
}`enter code here`
# Run the application
shinyApp(ui = ui, server = server)
Код работает отлично, и я могу вводить новые данные, как и когда я хочу хорошо, но когда я нажимаю кнопку «новый», чтобы очистить данные, чтобы я хотел ввести новый набор деталей, приложение закрывается, давая следующая ошибка
Warning: Error in UpdateInputs: could not find function "UpdateInputs"
Предупреждение не закрывает приложение, пока не будет нажата новая кнопка. Что мне не хватает? Пожалуйста помоги. Спасибо.