在创建一个闪亮的应用程序来根据用户输入获取数据框时,我使用以下方法,效果很好:
library(shiny)
ui <- fluidPage(
textInput("name", "Comnnay 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"),
#Table showing what is there in the data frame
tableOutput("table"),
#Button which appends row to the existing dataframe
actionButton("Action", "Submit"),
#Button to save the file
downloadButton('downloadData', 'Download')
)
library(shiny)
server <- function(input, output){
#Global variable to save the data
Data <- data.frame()
Results <- reactive(data.frame(input$name, input$income, input$expenditure,
input$date , 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)
})
output$downloadData <- downloadHandler(
# Create the download file name
filename = function() {
paste("data-", Sys.Date(), ".csv", sep="")
},
content = function(file) {
write.csv(Data, file) # put Data() into the download file
})
}
shinyApp(ui = ui, server = server)
我该怎么做才能更改输出版本。还是我必须特别指定一些内容?谢谢。
答案 0 :(得分:1)
大多数语言中的所有日期均为数字,这是预期的。如果您只想将字符串解析为
Results <- reactive(data.frame(input$name, input$income, input$expenditure,
as.character(input$date), as.character(Sys.Date())))