shiny_pixels_output: Shiny Widget Output

Description Usage Arguments Examples

View source: R/shiny.R

Description

Provides a Shiny Widget for Output.

Usage

1
shiny_pixels_output(outputId, width = "100%", height = "400px")

Arguments

outputId

The identifier for this widget.

width

The width for this widget.

height

The height for this widget.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
library(shiny)

ui <- fluidPage(
  tags$head(
    tags$style(HTML("
      #pixels {
        height: 270px !important;
        margin-top: 10px;
      }
    "))
  ),
  titlePanel("Digit Capture Application"),
  textOutput("prompt"),
  shiny_pixels_output("pixels"),
  actionButton("captureDigit", "Capture")
)

server <- function(input, output) {
  output$pixels <- shiny_render_pixels(
    show_pixels()
  )

  digit <- reactiveVal(floor(runif(1, 1, 10)))
  output$prompt <- renderText(paste0("Please draw number ", digit(), ":"))

  observeEvent(input$captureDigit, {
    digit_path <- file.path("digits", digit())
    if (!dir.exists(digit_path)) dir.create(digit_path, recursive = TRUE)
    saveRDS(input$pixels, paste0(digit_path, "/", as.numeric(Sys.time()), ".rds"))
 
    digit(floor(runif(1, 1, 10)))
    output$pixels <- shiny_render_pixels(
      show_pixels()
    )
  })
}

if (interactive()) {
  shinyApp(ui = ui, server = server)
}

pixels documentation built on Dec. 4, 2020, 5:07 p.m.