始める無料で始める

Adding inputs

Inputs are Shiny's way of allowing users to interact with an app. For example, textInput() is used to let the user enter text and numericInput() lets the user select a number. In the next chapter we will see many other types of inputs.

To add an input to your app, simply add the input function inside fluidPage(). Recall from the video that all input functions have the same first two arguments: inputId and label.

この演習はコースの一部です

Case Studies: Building Web Applications with Shiny in R

コースを見る

演習の手順

  • Define the UI for the Shiny application.
  • Create a numeric input with ID "age" and a descriptive label of "How old are you?".
  • Create a text input with ID "name" and a label of "What is your name?".

実践的なインタラクティブ演習

このサンプルコードを完成させて、この演習に挑戦してみましょう。

library(shiny)

# Define UI for the application
ui <- ___(
  # Create a numeric input with ID "age" and label of
  # "How old are you?"
  numericInput(___, ___, value = 20),
  
  # Create a text input with ID "name" and label of 
  # "What is your name?"
  ___(___, ___)
)

# Define the server logic
server <- function(input, output) {}

# Run the application
shinyApp(ui = ui, server = server)
コードを編集して実行