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

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

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.

require(shiny)

runApp(list(ui = pageWithSidebar(
  headerPanel("Creating frile"),
  sidebarPanel(
    selectInput("var",
                label = "Drops",
                choices = c("Op1", "Op2", "Op3", "Op4"),
                selected = "Op1"),
    sliderInput("range",
                label = "Slide to select",
                min = 0, max = 100, value = c(0, 100)),
    actionButton("button", "Export file")
  ),
  mainPanel(htmlOutput("text")
  )
),

server = function(input, output) {
  output$text <- renderUI({
    str1 <- paste("You have selected:", input$var)
    str2 <- paste("The range that goes between:",
                  input$range[1], "to", input$range[2])
    HTML(paste(str1, str2, sep = '<br/>'))
  })
  
}

)

)

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

你可以这样做:

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

You can do something like that:

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

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:

确定