การรวมแหล่งข้อความทั้งหมด

กรณีศึกษา: การสร้างเว็บแอปพลิเคชันด้วย Shiny ใน R

Dean Attali

Shiny Consultant

การรวมแหล่งข้อความทั้งหมด

  • แหล่งข้อมูล 3 แหล่งสำหรับ word cloud

    • Text object: artofwar
    • ข้อความจากผู้ใช้: textAreaInput()
    • ไฟล์ข้อความ: fileInput()
  • ขั้นตอนถัดไป: ใช้งานทั้งหมดพร้อมกัน

    • Radio buttons สำหรับเลือกแหล่งข้อความ

กรณีศึกษา: การสร้างเว็บแอปพลิเคชันด้วย Shiny ใน R

Radio buttons - ทบทวน

radioButtons(
    "time_of_day", "Choose your favorite time of day",
    choices = c("Morning", "Afternoon", "Evening"),
    selected = "Afternoon"
)

กรณีศึกษา: การสร้างเว็บแอปพลิเคชันด้วย Shiny ใน R

Radio buttons - ขั้นสูง

radioButtons(
    "time_of_day", "Choose your favorite time of day",
    choices = c("I'm a morning person!" = "Morning",
                "Love my afternoons"    = "Afternoon",
                "Night owl here!"       = "Evening"),
    selected = "Afternoon"
)

str(input$time_of_day)
chr "Afternoon"
กรณีศึกษา: การสร้างเว็บแอปพลิเคชันด้วย Shiny ใน R

Conditional panels

  • แสดง/ซ่อน UI ตามค่า input
conditionalPanel(condition, ...)
  • condition คล้ายกับโค้ด R แต่ใช้ input.<id> แทน input$<id>
  • ... คือ UI ใดก็ได้
กรณีศึกษา: การสร้างเว็บแอปพลิเคชันด้วย Shiny ใน R

Conditional panels

ui <- fluidPage(
  radioButtons("time_of_day",
               "Choose your favorite time of day",
               ...),

  plotOutput("morning_only_plot")
)
ui <- fluidPage(
  radioButtons("time_of_day",
               "Choose your favorite time of day",
               ...),

  conditionalPanel(
    condition = "input.time_of_day == 'Morning'",
    plotOutput("morning_only_plot")
  )
)
กรณีศึกษา: การสร้างเว็บแอปพลิเคชันด้วย Shiny ใน R

มาฝึกกันเถอะ!

กรณีศึกษา: การสร้างเว็บแอปพลิเคชันด้วย Shiny ใน R

Preparing Video For Download...