Display a random Emily Dickinson poem (Gutenberg edition) |
This small Shiny application demonstrates how Shiny can be used to display a random poem from the gutenberg edition of her poems.
shinyServer(function(input, output) {
output$displaypoem <- renderPrint({
input$pickpoem
require(mosaic)
directory <- "gutenberg"
files <- list.files(directory)
n <- length(files)
randnum <- sample(1:n, 1)
lines <- readLines(paste(directory, "/", files[randnum], sep=""))
for (i in 1:length(lines)) {
cat(paste(lines[i], "\n"))
}
})
}
)