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

相关推荐
idolao4 天前
R语言4.4.3统计分析软件安装教程:详细步骤+自定义安装路径(64位)
开发语言·r语言
做cv的小昊4 天前
【TJU】应用统计学——第四周作业(2.3 C-R不等式、2.4区间估计)
c语言·人工智能·算法·机器学习·数学建模·r语言·概率论
爱技术的阿呆6 天前
R code debug 和 study
开发语言·r语言
Q一件事6 天前
R语言制图-相关性及关系网络图
开发语言·r语言
weixin_446934037 天前
多分类暴露变量的亚组分析森林图功能上线了,R语言搞不了风暴统计平台一键搞定
人工智能·机器学习·分类·数据挖掘·r语言
天桥下的卖艺者7 天前
R语言使用TrialEmulation包快速进行数据模拟RCT研究(真实世界研究)
开发语言·r语言·模拟rct
Omics Pro7 天前
基因集(模块)活性量化:R语言+Java原生
大数据·开发语言·前端·javascript·数据库·r语言·aigc
开开心心就好8 天前
伪装文件历史记录!修改时间的黑科技软件
java·前端·科技·r语言·edge·pdf·语音识别
xiaoliuliu123459 天前
R语言4.5.0安装教程:详细步骤+自定义安装路径(64位)
开发语言·r语言