Çıktı türleri

shinydashboard ile Panolar Oluşturma

Png Kee Seng

Researcher

Output ve render işlevleri

  • Bir shinyApp’te çıktılar vardır
  • Her çıktı için iki işlev çağrılır

    • İlki UI içindeki bir işlevdir
    • Bu, çıktının nereye yerleşeceğini belirler
    • Tipik biçimi:
      <type>output(<identifying label>, ...)
      
  • İkinci kod server içinde tanımlanır

    • Biçimi şöyledir:
      output$<identifying label> <- render<type>(...)
      
shinydashboard ile Panolar Oluşturma

Örnek: Uyku çalışması

  • Önce veri setini içe aktaralım
    library(tidyverse)
    sleep <- read_csv("../data/Time Americans Spend Sleeping.csv")  
    
  • Sütunlar şunlardır
    $ index                   : num [1:945] 0 1 2 3 4  ...
    $ Year                    : num [1:945] 2003 2004 2005 2006 2007 ...
    $ Period                  : chr [1:945] "Annual" "Annual" "Annual" "Annual" ...
    $ Avg hrs per day sleeping: num [1:945] 8.57 8.55 8.62 8.63  ...
    $ Standard Error          : num [1:945] 0.018 0.026 0.023 0.024  ...
    $ Type of Days            : chr [1:945] "All days" "All days" "All days" ...
    $ Age Group               : chr [1:945] "15 years and over" "15 years and over" ...
    $ Activity                : chr [1:945] "Sleeping" "Sleeping" "Sleeping" ...
    $ Sex                     : chr [1:945] "Both" "Both" "Both" ...
    
shinydashboard ile Panolar Oluşturma

textOutput

  • Önce UI içine textOutput yerleştirelim
ui <- fluidPage(
  titlePanel("Sleeping habits in America"), 
  textOutput("textlabel"))

server <- function(input, output) {
}

shinyApp(ui, server)
shinydashboard ile Panolar Oluşturma

renderText

  • Metin çıktısını üretmek için server’da renderText kullanın
  • output$ gösterimini kullanacağız
ui <- fluidPage(
  titlePanel("Sleeping habits in America"), 
  textOutput("textlabel"))

server <- function(input, output) { output$textlabel <- renderText("Uyku yoksunluğu dünyadaki birçok büyük şehirde ciddi bir sağlık sorunudur.") }
shinyApp(ui, server)
shinydashboard ile Panolar Oluşturma

textOutput render edildi

girdi etkileşimi olmayan metin çıktısı demosu.

shinydashboard ile Panolar Oluşturma

Etkileşimli textOutput

  • Girdi ve çıktılar arasında etkileşim için girdilere input$ ile erişiriz
input$<type>
shinydashboard ile Panolar Oluşturma

Etkileşimli textOutput

  • Örnek olarak bir metin girdisini ele alalım.
ui <- fluidPage(
  titlePanel("Sleeping habits in America"), 

textInput("textlabel", "Adınızı yazınız", value = "", placeholder = "Don"),
textOutput("textoutlabel")) server <- function(input, output) { output$textoutlabel <- renderText(paste0("Merhaba ",
input$textlabel,
"Uyku yoksunluğu dünyadaki birçok büyük şehirde ciddi bir sağlık sorunudur.")) } shinyApp(ui, server)
shinydashboard ile Panolar Oluşturma

Etkileşimli textOutput

etkileşimli metin çıktısı.

shinydashboard ile Panolar Oluşturma

plotOutput

  • UI içinde plotOutput() yerleştirin
ui <- fluidPage(
  titlePanel("Sleeping habits in America"), 

plotOutput("plotlabel"))
server <- function(input, output) { } shinyApp(ui, server)
shinydashboard ile Panolar Oluşturma

renderPlot

  • server() içinde renderPlot() kullanacağız
ui <- fluidPage(
  titlePanel("Sleeping habits in America"), 
  plotOutput("plotlabel"))

server <- function(input, output) {

output$plotlabel <- renderPlot({ ggplot(sleep) + geom_histogram(aes(x = `Avg hrs per day sleeping`)) })
} shinyApp(ui, server)
shinydashboard ile Panolar Oluşturma

plotOutput render edildi

plotoutput demosu.

shinydashboard ile Panolar Oluşturma

selectInput ile plotOutput

  • Kullanıcı girdileri farklı sonuçlar üretebilir
ui <- fluidPage(
  titlePanel("Sleeping habits in America"), 
  selectInput("selectlabel", 
              "Bir seçenek seçin",
              choices = c("Histogram", "Boxplot")),
  plotOutput("plotlabel"))
shinydashboard ile Panolar Oluşturma

selectInput ile plotOutput

server <- function(input, output) {
  output$plotlabel <- renderPlot({
    if (input$selectlabel == "Histogram"){

ggplot(sleep) + geom_histogram(aes(x = `Avg hrs per day sleeping`))
} else if (input$selectlabel == "Boxplot"){
ggplot(sleep) + geom_boxplot(aes(x = `Avg hrs per day sleeping`))
} }) } shinyApp(ui, server)
shinydashboard ile Panolar Oluşturma

selectInput ile plotOutput

selectInput ile plotOutput demosu

shinydashboard ile Panolar Oluşturma

sliderInput ile plotOutput

  • Şimdi sliderInput içeren bir örneğe bakalım
ui <- fluidPage(
  titlePanel("Sleeping habits in America"), 

sliderInput("sliderlabel", "Ortalama uyku süresi", min = 7.5, max = 11, value = c(7.5, 11), step = 0.02),
plotOutput("plotlabel")) server <- function(input, output) {
output$plotlabel <- renderPlot({ filter(sleep, `Avg hrs per day sleeping` >= input$sliderlabel[1], `Avg hrs per day sleeping` <= input$sliderlabel[2]) %>% ggplot() + geom_boxplot(aes(x=`Avg hrs per day sleeping`)) })
} shinyApp(ui, server)
shinydashboard ile Panolar Oluşturma

sliderInput ile plotOutput

sliderInput ile plotoutput demosu

shinydashboard ile Panolar Oluşturma

shiny’de simgeler

  • shiny, shinyApp’te kullanılabilecek simgeler de içerir

shiny’de bazı simgeler

1 https://fontawesome.com/icons
shinydashboard ile Panolar Oluşturma

shiny’de simgeler: Bir örnek

  • icon("...") kullanın
  • Önceki örneği anımsayınız
  • Örn., icon("bed")
ui <- fluidPage(
  titlePanel("Sleeping habits in America"), 
  sliderInput("sliderlabel",

list(icon("bed"),
"Bir seçenek seçin:"), min = 7.5, max = 11, value = c(7.5, 11), step = 0.02), plotOutput("plotlabel")) server <- function(input, output) { output$plotlabel <- renderPlot({ filter(sleep, `Avg hrs per day sleeping` >= input$sliderlabel[1], `Avg hrs per day sleeping` <= input$sliderlabel[2]) %>% ggplot() + geom_boxplot(aes(x=`Avg hrs per day sleeping`)) }) } shinyApp(ui, server)
shinydashboard ile Panolar Oluşturma

Simgeyle oluşturulan uygulama

Simge demosu

shinydashboard ile Panolar Oluşturma

Haydi pratik yapalım!

shinydashboard ile Panolar Oluşturma

Preparing Video For Download...