英文:
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 <- paste("You have selected:", input$var)
str2 <- paste("The range that goes between:",
input$range[1], "to", input$range[2])
writeLines(c(str1, str2), "path/to/file.txt")
})
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论