İ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:
- Uyku saatlerinin dağılımı
- 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
Egzersiz talimatları
mainPaneliçine "histogram" ve "barchart" adlı iki grafik çıktısı ekle.checkboxGroupInput()içindekichoiceNamesargümanında, içeriğini "calendar", "briefcase" ve "gift" adlı ikonlarla değiştir.- Biri
histogram, diğeribarchartadlı 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
___