【发布时间】:2018-07-03 07:58:24
【问题描述】:
在创建闪亮的应用程序以根据用户输入获取数据框时,我使用以下内容,效果非常好:
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)
如何更改输出版本。还是我必须特别指定一些东西?谢谢。
【问题讨论】: