Display a random Emily Dickinson poem (Gutenberg edition)


            
show with app
  • server.R
  • ui.R


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"))
     }
     })
  }
)
library(shiny)

shinyUI(fluidPage(
  # Application title
  titlePanel("Display a random Emily Dickinson poem (Gutenberg edition)"),

  sidebarLayout(
    sidebarPanel(
      actionButton("pickpoem", "Pick a poem at random")),
# Show a plot of the generated distribution
    mainPanel(verbatimTextOutput("displaypoem"))
  )
))