Ieșiri

Crearea aplicațiilor web cu Shiny în R

Kaelen Medeiros

Data Scientist

Funcții render

ui <- fluidPage(
  textInput("name", "Enter a name:"),
  selectInput("animal", "Dogs or cats?", choices = c("dogs", "cats")),
  textOutput("question"),
  textOutput("answer")
)

server <- function(input, output, session) {
  output$question <- renderText({
    paste("Do you prefer dogs or cats,", input$name, "?")
  })
  output$answer <- renderText({
    paste("I prefer", input$animal, "!")
  })
}
Crearea aplicațiilor web cu Shiny în R

Alte funcții render

Crearea aplicațiilor web cu Shiny în R

Funcții output

ui <- fluidPage(
  textInput("name", "Enter a name:"),
  selectInput("animal", "Dogs or cats?", choices = c("dogs", "cats")),

textOutput("question"), textOutput("answer")
)
Crearea aplicațiilor web cu Shiny în R

Alte funcții output

  • tableOutput() or dataTableOutput
  • imageOutput()
  • plotOutput()
Crearea aplicațiilor web cu Shiny în R

Funcții output și render non-Shiny

library(shiny)
library(babynames)

ui <- fluidPage(
  DT::DTOutput("babynames_table")
)

server <- function(input, output){
  output$babynames_table <- DT::renderDT({
    babynames %>% 
      dplyr::slice_sample(prop = .1) %>%
      DT::datatable()
  })
}

shinyApp(ui = ui, server = server)

Tabel de date interactiv afișând un eșantion aleatoriu de 10% din setul de date babynames

Crearea aplicațiilor web cu Shiny în R

Să exersăm!

Crearea aplicațiilor web cu Shiny în R

Preparing Video For Download...