BaşlayınÜcretsiz başlayın

İlk shinyApp'in

Girdi ve çıktıları bir shinyApp içinde nasıl bir araya getirebileceğini gördün. Ayrıca, bir shinyApp'in uyku çalışmasının sonuçlarını iletecek şekilde nasıl kurgulanabileceğini de inceledin.

Hedefin şimdi iki ana sonucu raporlayan bir shinyApp oluşturmak:

  1. Uyku saatlerinin dağılımı
  2. Farklı yaş gruplarında medyan uyku saati

Bu egzersizde verileri sleep adlı bir dplyr veri çerçevesinde depoladık ve shiny ile tidyverse kütüphaneleri zaten yüklendi.

Şimdi kendi shinyApp'ini oluşturma sırası sende!

Bu egzersiz, kursun bir parçasıdır

shinydashboard ile Panolar Oluşturma

Kursa Göz Atın

Egzersiz talimatları

  • mainPanel içine "histogram" ve "barchart" adlı iki grafik çıktısı ekle.
  • checkboxGroupInput() içindeki choiceNames argümanında, içeriğini "calendar", "briefcase" ve "gift" adlı ikonlarla değiştir.
  • Biri histogram, diğeri barchart adlı iki çıktıyı tanımla.
  • Shiny uygulamasını çalıştırmak için shinyApp() fonksiyonunu kullan.

Uygulamalı etkileşimli egzersiz

Bu egzersizi bu örnek kodu tamamlayarak deneyin.

ui <- fluidPage(
  titlePanel("Sleeping habits in America"), 
  fluidRow(
  # Place two plots here, called "histogram" and "barchart"
  mainPanel(___("histogram"), ___("barchart")), 
  inputPanel(sliderInput("binwidth", 
                         label = "Bin width", 
                         min = 0.1, max = 2, 
                         step = 0.01, value=0.25),
             checkboxGroupInput("days", "Choose types of days:",
                                # Replace the list elements with icons called "calendar", "briefcase" and "gift"
                                choiceNames = list("All days", 
                                                   "Non-holiday weekdays", 
                                                   "Weekend days/holidays"), 
                                choiceValues = list("All days", 
                                                    "Nonholiday weekdays", 
                                                    "Weekend days and holidays"))), 
  "In general, across the different age groups, Americans seem to get adequate daily rest." ))

server <- function(input, output, session) {
  # Define the histogram and barchart
  output$histogram <- ___({
    ggplot(sleep, aes(x=`Avg hrs per day sleeping`)) + 
    geom_histogram(binwidth = input$binwidth, col='white') + 
    theme_classic()
  })
  ___ <- ___({
    filter(sleep, `Type of Days` %in% input$days) %>%
      group_by(`Type of Days`, `Age Group`) %>%
      summarize(`Median hours` = median(`Avg hrs per day sleeping`)) %>%
      ggplot(aes(x = `Median hours`, y = `Age Group`, fill = `Type of Days`)) +
      geom_col(position = 'dodge') + theme_classic()
  })
}

# Use shinyApp() to render the shinyApp
___
Kodu Düzenle ve Çalıştır