시작하기무료로 시작하기

볼 대륙 선택하기

데이터셋을 탐색할 때는 둘 이상의 변수를 함께 필터링해 보는 것이 유용할 때가 많아요. 예를 들어, 특정 기대수명을 가진 아프리카 국가의 데이터만 보고 싶을 수 있어요.

이 연습은 강의의 일부입니다

사례 연구: R의 Shiny로 웹 애플리케이션 만들기

강의 보기

연습 안내

사용자가 특정 대륙을 선택해 볼 수 있도록 select 입력을 추가하세요. 구체적으로:

  • UI에 ID가 "continent"이고 라벨이 "Continent"인 select 입력을 추가하세요.
  • render 함수 안에서 대륙 입력값을 사용해 선택한 대륙의 데이터만 선택하세요(21행).

실습형 인터랙티브 연습

이 예제를 이 샘플 코드를 완성하여 풀어보세요.

ui <- fluidPage(
  h1("Gapminder"),
  sliderInput(inputId = "life", label = "Life expectancy",
              min = 0, max = 120,
              value = c(30, 50)),
  # Add a continent selector dropdown
  ___(___, ___, choices = levels(gapminder$continent)),
  tableOutput("table")
)

server <- function(input, output) {
  output$table <- renderTable({
    data <- gapminder
    data <- subset(
      data,
      lifeExp >= input$life[1] & lifeExp <= input$life[2]
    )
    data <- subset(
      data,
      # Filter the data according to the continent input value
      continent == ___
    )
    data
  })
}

shinyApp(ui, server)
코드 편집 및 실행