Get startedGet started for free

Upload a text file (ui)

Rather than typing a long piece of text into a box, it can be more convenient to upload a text file if the text is extremely long.

Uploading files to a Shiny app is done using fileInput().

This exercise is part of the course

Case Studies: Building Web Applications with Shiny in R

View Course

Exercise instructions

Add a file input to the Shiny app with an input ID of "file" and a label of "Select a file".

Hands-on interactive exercise

Have a go at this exercise by completing this sample code.

ui <- fluidPage(
  h1("Word Cloud"),
  sidebarLayout(
    sidebarPanel(
      textAreaInput("text", "Enter text", rows = 7),
      # Add a file input
      ___,
      numericInput("num", "Maximum number of words",
                   value = 100, min = 5),
      colourInput("col", "Background color", value = "white")
    ),
    mainPanel(
      wordcloud2Output("cloud")
    )
  )
)

server <- function(input, output) {
  output$cloud <- renderWordcloud2({
    create_wordcloud(input$text, num_words = input$num,
                     background = input$col)
  })
}

shinyApp(ui = ui, server = server)
Edit and Run Code