Mastering Shiny 08 User feedback

文章目录

  • [8 User feedback](#8 User feedback)
    • [8.1 Validation](#8.1 Validation)
      • [8.1.1 Validating input](#8.1.1 Validating input)
      • [8.1.2 Cancelling execution with `req()`](#8.1.2 Cancelling execution with req())
      • [8.1.3 `req()` and validation](#8.1.3 req() and validation)
      • [8.1.4 Validate output](#8.1.4 Validate output)
    • [8.2 Notifications](#8.2 Notifications)
      • [8.2.1 Transient notification](#8.2.1 Transient notification)
      • [8.2.2 Removing on completion](#8.2.2 Removing on completion)
      • [8.2.3 Progressive updates](#8.2.3 Progressive updates)
    • [8.3 Progress bars](#8.3 Progress bars)
      • [8.3.1 Shiny](#8.3.1 Shiny)
      • [8.3.2 Waiter](#8.3.2 Waiter)
      • [8.3.3 Spinners](#8.3.3 Spinners)
    • [8.4 Confirming and undoing](#8.4 Confirming and undoing)
      • [8.4.1 Explicit confirmation](#8.4.1 Explicit confirmation)
      • [8.4.2 Undoing an action](#8.4.2 Undoing an action)
      • [8.4.3 Trash](#8.4.3 Trash)
    • [8.5 Summary](#8.5 Summary)

8 User feedback

8.1 Validation

8.1.1 Validating input

复制代码
library(shiny);ui <- fluidPage(
  shinyFeedback::useShinyFeedback(),
  numericInput("n", "n", value = 10),
  textOutput("half")
)
server <- function(input, output, session) {
  half <- reactive({
    even <- input$n %% 2 == 0
    shinyFeedback::feedbackWarning("n", !even, "Please select an even number")
    input$n / 2    
  })
  output$half <- renderText(half())
};shinyApp(ui,server)

8.1.2 Cancelling execution with req()

复制代码
ui <- fluidPage(
  selectInput("language", "Language", choices = c("", "English", "Maori")),
  textInput("name", "Name"),
  textOutput("greeting")
)
server <- function(input, output, session) {
  greetings <- c(
    English = "Hello", 
    Maori = "Kia ora"
  )
  output$greeting <- renderText({
    req(input$language, input$name)
    paste0(greetings[[input$language]], " ", input$name, "!")
  })
}
}

8.1.3 req() and validation

复制代码
library(shiny);ui <- fluidPage(
  shinyFeedback::useShinyFeedback(),
  textInput("dataset", "Dataset name"), 
  tableOutput("data")
)
server <- function(input, output, session) {
  data <- reactive({
    req(input$dataset)
    exists <- exists(input$dataset, "package:datasets")
    shinyFeedback::feedbackDanger("dataset", !exists, "Unknown dataset")    
    req(exists, cancelOutput = T)
    get(input$dataset, "package:datasets")
  })
  output$data <- renderTable({
    head(data())
  })
};shinyApp(ui,server)

8.1.4 Validate output

复制代码
ui <- fluidPage(
  numericInput("x", "x", value = 0),
  selectInput("trans", "transformation", 
    choices = c("square", "log", "square-root")
  ),
  textOutput("out")
)
server <- function(input, output, session) {
  output$out <- renderText({
   	if (input$x < 0 && input$trans %in% c("log", "square-root")) {
      validate("x can not be negative for this transformation")
    }
    switch(input$trans,
      square = input$x ^ 2,
      "square-root" = sqrt(input$x),
      log = log(input$x)
    )
  })
};shinyApp(ui,server)

8.2 Notifications

复制代码
ui <- fluidPage(
  actionButton("goodnight", "Good night")
)
server <- function(input, output, session) {
  observeEvent(input$goodnight, { 
    showNotification("So long") 
    Sys.sleep(1)
    showNotification("Farewell")
    Sys.sleep(1)
    showNotification("Auf Wiedersehen")
    Sys.sleep(1)
    showNotification("Adieu")
  })
};shinyApp(ui,server)

8.2.1 Transient notification

8.2.2 Removing on completion

8.2.3 Progressive updates

8.3 Progress bars

8.3.1 Shiny

8.3.2 Waiter

8.3.3 Spinners

8.4 Confirming and undoing

8.4.1 Explicit confirmation

8.4.2 Undoing an action

8.4.3 Trash

8.5 Summary

相关推荐
zhangfeng11334 小时前
提示 R for Windows front-end 怎么被防火墙 阻止了 Rscript.exe` 和 `R.exe`区别
windows·r语言·php
全栈开发圈9 小时前
新书速览|R语言医学数据分析与可视化
开发语言·数据分析·r语言
木与长清1 天前
人鼠同源基因离线转换
数据库·矩阵·数据分析·r语言
HP-Patience1 天前
【Rmarkdown】快速入门
r语言
HP-Patience1 天前
【Data Mining】01抽样技术
人工智能·数据挖掘·r语言
lihihi2 天前
P1650 [ICPC 2004 Shanghai R] 田忌赛马(同洛谷2587)
开发语言·算法·r语言
请叫我大虾2 天前
数据结构与算法-分裂问题,将数字分成0或1,求l到r之间有多少个1.
java·算法·r语言
MOON404☾2 天前
R语言EDA学习笔记
笔记·学习·数据分析·r语言·eda
AI科技星2 天前
v=c空间光速螺旋量子几何归一化统一场论——全维度ω、r、f推导G与c的终极关联及严格证明
开发语言·opencv·r语言
Katecat9966318 天前
【计算机视觉】基于Faster R-CNN的线段检测与分割实现
计算机视觉·r语言·cnn