【问题标题】:Transfer user input into csv file in rshiny [closed]将用户输入传输到 rshiny 中的 csv 文件 [关闭]
【发布时间】:2017-07-19 04:17:06
【问题描述】:

在 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

【问题讨论】:

  • 获取所有输入字段并构建 csv?
  • 是的@RomanLuštrik,但我不知道该怎么做

标签: r csv shiny


【解决方案1】:

您可以将数据存储为响应式表达式中的数据框,并使用下载按钮和下载处理程序下载数据。

服务器.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)

    })


})

ui.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")
    )
  )
))

希望这会有所帮助!

【讨论】:

  • 谢谢你,弗洛里安!这很有帮助,而且效果很好。是否有另一个版本没有下载按钮,用户无法取回 CSV 文件。我想知道,因为我正在将其传输到元文件中
  • 很高兴我能帮上忙。除了下载按钮和下载处理程序,您还可以使用操作按钮和观察事件,并使用 write.csv 将文件存储在您的服务器上。
  • 这样的? UI ---- actionButton('action', 'Data') ||服务器 ----- output$action
  • 服务器部分应如下所示: output$action
猜你喜欢
  • 1970-01-01
  • 2019-07-24
  • 1970-01-01
  • 2023-03-12
  • 2021-02-28
  • 2019-10-17
  • 2013-08-22
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多