1
votes

In my shiny application, I would like to have a textarea field that allows the users to give text input. This can be done with:

ui.R:
tags$textarea(id="item",rows=3,cols=40,placeholder="Type your message...")
verbatimTextOutput("news")

server.R:
output$news <- renderText(input$item)

With this code, I can only see the text input within the current session of the app. My goal is, to save user text input permanently in the app (user gives text input, submits and data will be displayed in the app permanently). Is this possible with shiny? My idea was to store the data in a global way like googlesheets.

1
Initial value could be read from an empty file, then every text entry gets appended?zx8754
You can save a variable globally using <<- instead of <-. If you want each user to have specific save, then you should look at [shiny.rstudio.com/reference/shiny/latest/session.html] (sessioninfo) and bind it to each userPork Chop

1 Answers

0
votes

One option is to write the text entry to disk as a plain text file, likely each time the user chooses to (e.g., by hitting a "Submit" button). You can use an actionButton and have an observeEvent that includes the code to save to disk.

Note that you will need to have unique file names to avoid overwriting. You could either use time stamps or take a look at the uuid package to generate random names.

If you are more comfortable with databases, you could, alternatively, set up a SQL table and append a line for each user submission (this would be substantially more reliable, allow you to store meta data with it, and avoid the file naming issues above).

Shiny itself is not designed to store data, though the authors have written up some suggested approaches (available here).