Last active
April 12, 2017 08:14
-
-
Save trestletech/3679b34c5a83f521387b to your computer and use it in GitHub Desktop.
Demonstration of file-system persistence in ShinyApps.io.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| .Rproj.user | |
| .Rhistory | |
| .RData |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Remeo: hi there! | |
| Juliet: oh hi! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| library(shiny) | |
| # Read in the log file from the local filesystem. | |
| # Because this is outside of `shinyServer`, it will be shared | |
| # between ALL users connected to this process. | |
| log <- readChar("log.txt", 1024) | |
| shinyServer(function(input, output, session) { | |
| # Format the log to include the existing log + all comments | |
| logText <- reactive({ | |
| if (is.null(input$name) || input$name == ""){ | |
| # There's nothing new to update here, just return the existing log. | |
| return(log) | |
| } | |
| # Format the new entry | |
| newEntry <- paste0(input$name, ": ", input$comment, "\r\n") | |
| log <<- paste0(log, newEntry) | |
| # Write the text file out | |
| writeChar(log, "log.txt") | |
| return(log) | |
| }) | |
| # Render the output log | |
| output$log <- renderText({ | |
| txt <- logText() | |
| # Clear out the current value | |
| updateTextInput(session, "name", value="") | |
| updateTextInput(session, "comment", value="") | |
| txt | |
| }) | |
| }) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| library(shiny) | |
| shinyUI(fluidPage( | |
| # Application title | |
| titlePanel("Demonstration of file persistence in Shiny"), | |
| # Define the side-panel | |
| sidebarLayout( | |
| sidebarPanel( | |
| textInput("name", "Name:"), | |
| textInput("comment", "Comment:"), | |
| submitButton("Comment") | |
| ), | |
| mainPanel( | |
| verbatimTextOutput("log") | |
| ) | |
| ) | |
| )) |
Is there a way, to download this log.txt file somehow from shinyapps.io when I am not displaying this file on my app?
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This demo can not be deployed to shinyapps.io since RAmazonS3 package has to be installed from CRAN, BioConductor or GitHub.