輸出

使用 R 的 Shiny 建立網頁應用程式

Kaelen Medeiros

Data Scientist

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, "!")
  })
}
使用 R 的 Shiny 建立網頁應用程式

其他 render 函式

使用 R 的 Shiny 建立網頁應用程式

輸出函式

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

textOutput("question"), textOutput("answer")
)
使用 R 的 Shiny 建立網頁應用程式

其他輸出函式

  • tableOutput()dataTableOutput
  • imageOutput()
  • plotOutput()
使用 R 的 Shiny 建立網頁應用程式

非 Shiny 的輸出與 render 函式

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)

互動式資料表,顯示 babynames 資料集隨機的 10% 樣本

使用 R 的 Shiny 建立網頁應用程式

一起來練習吧!

使用 R 的 Shiny 建立網頁應用程式

Preparing Video For Download...