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

Etkileşimli öğelerle ilk shinydashboard'un

Bir shinydashboard içine etkileşimli öğelerin nasıl eklenebileceğini ve etkileşimli veri tablolarının nasıl dahil edilebileceğini gördün.

Bu egzersizde, Airbnb ilanları listings adlı bir veri çerçevesinde, coğrafi harita ise m_london adlı bir leaflet nesnesinde saklandı. Üst başlık ve yan çubuk da sırasıyla header ve sidebar olarak saklandı.

Özel yardımcı fonksiyonlar:

  • make_plots: Kutu grafikleri (box plot) veya keman grafikleri (violin plot) çizer
  • num_listings: Seçilen aralığa göre ilan sayısını hesaplar
  • num_private_rooms: Seçilen aralığa göre tüm ilanlar içinde özel oda yüzdesini hesaplar
  • median_price: Seçilen aralığa göre medyan fiyatı hesaplar Bir yardımcı fonksiyon hakkında daha fazla bilgi almak için konsolda çalıştırabilirsin (örneğin make_plots).

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

shinydashboard ile Panolar Oluşturma

Kursa Göz Atın

Egzersiz talimatları

  • "plots" adlı bir plotly kutu/keman grafiği ekle.
  • "table" adlı bir veri tablosu ekle.
  • "map" adlı bir leaflet haritası ekle.
  • dashboardPage() içinde doğru argümanları ayarla.

Uygulamalı etkileşimli egzersiz

Bu egzersizi bu örnek kodu tamamlayarak deneyin.

body <- dashboardBody(
  tabItems(
    tabItem(tabName = "charts",
            fluidRow(
              valueBoxOutput(outputId = "count"), valueBoxOutput(outputId = "prop"),valueBoxOutput(outputId = "med") ),
            fluidRow(
              tabBox(side = "left", id = "tabset", height = "500px",
                     tabPanel("Charts", 
                              # Place plotly object here
                              fluidRow(box(___("plots", height = 500, width = 600)) ) ), 
                     # Place dataTable object here
                     tabPanel("Data table", height = "500px", ___("table")) ), 
              box(side = "right", height = "200px", title = "Welcome to London!",),
              box(side = "right", height = "385px", title = "Controls",
                  sliderInput(inputId = "range", label = "Select price range:",
                              min = 0, max = 25000,value = c(0,2500)),
                  selectInput(inputId = "select", label = "Select group:", 
                              choices = c("Box plots", "Violin plots")) ) ) ),
    tabItem(tabName = "map",
            # Place leaflet object here
            fluidRow(box(title = "Map of listings in London", ___("map", height = 600, width = 700))) ) ) ) 

# Set the correct arguments for dashboardPage()
ui <- dashboardPage(___, ___, ___) 

server <- function(input, output) {
  output$count <- renderValueBox(valueBox("Number of listings", num_listings(input$range), 
                                        icon = icon("house-user") ))
  output$prop <- renderValueBox(valueBox("Private rooms", paste0(num_private_rooms(input$range), "% of all listings"),
                                        icon = icon("eye"), color = "orange") )
  output$med <- renderValueBox(valueBox("Median price", paste0(median_price(input$range), "£"), 
                                        icon = icon("money-bill-alt"), color = "olive") )
  output$plots <- renderPlotly(make_plots(input$range, input$select))
  output$table <- renderDataTable(filter(listings, price >= input$range[1], price <= input$range[2]) %>% select(c(name, neighbourhood, room_type, price)), 
                                  options = list(lengthMenu = c(5, 30, 50)))
  output$map <- renderLeaflet(m_london)
}

shinyApp(ui, server)
Kodu Düzenle ve Çalıştır