LoslegenKostenlos loslegen

Use your own words

The textAreaInput() is useful when you want to allow the user to enter much longer text than what a typical textInput() allows. Textareas span multiple rows and have a vertical scrollbar, as well as a rows parameter that can determine how many rows are visible.

Except for being larger, textarea inputs behave very similar to text inputs in every other way.

Diese Übung ist Teil des Kurses

Case Studies: Building Web Applications with Shiny in R

Kurs anzeigen

Anleitung zur Übung

Your task is to add a textarea input to allow the user to create a word cloud using their own words. Specifically:

  • Add a text area input containing 7 rows with an inputId of "text" and a label of "Enter text".
  • Use the text area's value as the data source for the word cloud, rather than the artofwar book (line 20).

Interaktive Übung

Versuche dich an dieser Übung, indem du diesen Beispielcode vervollständigst.

ui <- fluidPage(
  h1("Word Cloud"),
  sidebarLayout(
    sidebarPanel(
      # Add a textarea 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({
    # Use the textarea's value as the word cloud data source
    create_wordcloud(data = ___, num_words = input$num,
                     background = input$col)
  })
}

shinyApp(ui = ui, server = server)
Code bearbeiten und ausführen