Đầu ra

Xây dựng ứng dụng web với Shiny trong R

Kaelen Medeiros

Data Scientist

Hàm 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, "!")
  })
}
Xây dựng ứng dụng web với Shiny trong R

Các hàm render khác

Xây dựng ứng dụng web với Shiny trong R

Hàm output

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

textOutput("question"), textOutput("answer")
)
Xây dựng ứng dụng web với Shiny trong R

Các hàm output khác

  • tableOutput() hoặc dataTableOutput
  • imageOutput()
  • plotOutput()
Xây dựng ứng dụng web với Shiny trong R

Hàm output và render ngoài 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)

Bảng dữ liệu tương tác hiển thị ngẫu nhiên 10% tập dữ liệu babynames

Xây dựng ứng dụng web với Shiny trong R

Ayo berlatih!

Xây dựng ứng dụng web với Shiny trong R

Preparing Video For Download...