Skip to content

Instantly share code, notes, and snippets.

@trestletech
Last active April 12, 2017 08:14
Show Gist options
  • Select an option

  • Save trestletech/3679b34c5a83f521387b to your computer and use it in GitHub Desktop.

Select an option

Save trestletech/3679b34c5a83f521387b to your computer and use it in GitHub Desktop.
Demonstration of file-system persistence in ShinyApps.io.
.Rproj.user
.Rhistory
.RData
Remeo: hi there!
Juliet: oh hi!
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
})
})
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")
)
)
))
@yongj
Copy link

yongj commented Feb 7, 2015

This demo can not be deployed to shinyapps.io since RAmazonS3 package has to be installed from CRAN, BioConductor or GitHub.

@MarcinKosinski
Copy link

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