Exporting/Saving output to a text file in a folder location

huangapple go评论108阅读模式
英文:

Exporting/Saving output to a text file in a folder location

问题

我想通过按下按钮实现的目标是:将文本文件保存在项目文件夹位置,例如/outputtext/。 有没有办法实现这个?

英文:

I want to create a file using various inputs and export the inputs in a text file in a local folder, say in /file/ in the project directory. I have the following working app.

  1. require(shiny)
  2. runApp(list(ui = pageWithSidebar(
  3. headerPanel("Creating frile"),
  4. sidebarPanel(
  5. selectInput("var",
  6. label = "Drops",
  7. choices = c("Op1", "Op2", "Op3", "Op4"),
  8. selected = "Op1"),
  9. sliderInput("range",
  10. label = "Slide to select",
  11. min = 0, max = 100, value = c(0, 100)),
  12. actionButton("button", "Export file")
  13. ),
  14. mainPanel(htmlOutput("text")
  15. )
  16. ),
  17. server = function(input, output) {
  18. output$text <- renderUI({
  19. str1 <- paste("You have selected:", input$var)
  20. str2 <- paste("The range that goes between:",
  21. input$range[1], "to", input$range[2])
  22. HTML(paste(str1, str2, sep = '<br/>'))
  23. })
  24. }
  25. )
  26. )

What I want to achive by the action button is: it will save a text file in a project folder location, e.g. /outputtext/. Any idea how to do this?

答案1

得分: 1

你可以这样做:

  1. observeEvent(input$button, {
  2. str1 <- paste("你选择了:", input$var)
  3. str2 <- paste("范围从:", input$range[1], "到", input$range[2])
  4. writeLines(c(str1, str2), "路径/到/文件.txt")
  5. })
英文:

You can do something like that:

  1. observeEvent(input$button, {
  2. str1 &lt;- paste(&quot;You have selected:&quot;, input$var)
  3. str2 &lt;- paste(&quot;The range that goes between:&quot;,
  4. input$range[1], &quot;to&quot;, input$range[2])
  5. writeLines(c(str1, str2), &quot;path/to/file.txt&quot;)
  6. })

huangapple
  • 本文由 发表于 2023年4月17日 16:16:45
  • 转载请务必保留本文链接:https://go.coder-hub.com/76033029.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定