将用户输入转移到r闪亮的[csv文件] [关闭]

问题描述 投票:1回答:1

在SHINY中,我们如何将用户输入从一些文本和数字框转移到CSV文件中?

流程将是:

- First the users input the information into those text boxes.
- Then the users press a Run button
- Upon pressing the button, a CSV file will be generated containing the information from those text boxes
r csv shiny
1个回答
1
投票

您可以将数据作为数据帧存储在反应式表达式中,并使用下载按钮和下载处理程序来下载数据。

server.R

library(shiny)

shinyServer(function(input, output, session) {

  dataReactive <- reactive({
data.frame(text = c(input$text1, input$text2, input$text3))

  })

  output$exampleTable <- DT::renderDataTable({
    dataReactive()
  })

  output$downloadData <- downloadHandler(
    filename = function() { 
      paste("dataset-", Sys.Date(), ".csv", sep="")
    },
    content = function(file) {
      write.csv(dataReactive(), file)

    })


})

长子。 R:

shinyUI(fluidPage(

  sidebarLayout(
    sidebarPanel(
      textInput("text1","Text 1:",value="example text 1"),
      textInput("text2","Text 2:",value="example text 2"),
      textInput("text3","Text 3:",value="example text 3"),
      downloadButton('downloadData', 'Download data')

    ),
    mainPanel(
                DT::dataTableOutput("exampleTable")
    )
  )
))

希望这可以帮助!

© www.soinside.com 2019 - 2024. All rights reserved.