LoslegenKostenlos loslegen

Word cloud Shiny app

You are provided with a sample dataset named artofwar, which contains the entire text of the Art of War book. You can inspect the given Art of War text by running head(artofwar) or tail(artofwar) to see the first and last few verses of the book.

As mentioned in the video, since word clouds are not an output you saw before, they require a new pair of output and render functions: wordcloud2Output() and renderWordcloud2(). These output functions are available from the wordcloud2 package.

Diese Übung ist Teil des Kurses

Case Studies: Building Web Applications with Shiny in R

Kurs anzeigen

Anleitung zur Übung

The function create_wordcloud(), the dataset artofwar, and all the necessary packages are available in your workspace.

  • Add a placeholder for a word cloud output to the UI, with an outputId of cloud.
  • Render the word cloud object and assign it to the correct item in the output list (line 11).

By the way, create_wordcloud() is a function we defined for you. You will not be able to run it in your own RStudio on your computer. If you want to have a look at it, type create_wordcloud in the console.

Interaktive Übung

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

# Define UI for the application
ui <- fluidPage(
  h1("Word Cloud"),
  # Add the word cloud output placeholder to the UI
  ___(outputId = "cloud")
)

# Define the server logic
server <- function(input, output) {
  # Render the word cloud and assign it to the output list
  output$___ <- ___({
    # Create a word cloud object
    create_wordcloud(artofwar)
  })
}

# Run the application
shinyApp(ui = ui, server = server)
Code bearbeiten und ausführen