Debian Codegraph @

inst/examples/05_sliders/app.R

raw
1 library(shiny)
2
3 # Define UI for slider demo app ----
4 ui <- fluidPage(
5
6 # App title ----
7 titlePanel("Sliders"),
8
9 # Sidebar layout with input and output definitions ----
10 sidebarLayout(
11
12 # Sidebar to demonstrate various slider options ----
13 sidebarPanel(
14
15 # Input: Simple integer interval ----
16 sliderInput("integer", "Integer:",
17 min = 0, max = 1000,
18 value = 500),
19
20 # Input: Decimal interval with step value ----
21 sliderInput("decimal", "Decimal:",
22 min = 0, max = 1,
23 value = 0.5, step = 0.1),
24
25 # Input: Specification of range within an interval ----
26 sliderInput("range", "Range:",
27 min = 1, max = 1000,
28 value = c(200,500)),
29
30 # Input: Custom currency format for with basic animation ----
31 sliderInput("format", "Custom Format:",
32 min = 0, max = 10000,
33 value = 0, step = 2500,
34 pre = "$", sep = ",",
35 animate = TRUE),
36
37 # Input: Animation with custom interval (in ms) ----
38 # to control speed, plus looping
39 sliderInput("animation", "Looping Animation:",
40 min = 1, max = 2000,
41 value = 1, step = 10,
42 animate =
43 animationOptions(interval = 300, loop = TRUE))
44
45 ),
46
47 # Main panel for displaying outputs ----
48 mainPanel(
49
50 # Output: Table summarizing the values entered ----
51 tableOutput("values")
52
53 )
54 )
55 )
56
57 # Define server logic for slider examples ----
58 server <- function(input, output) {
59
60 # Reactive expression to create data frame of all input values ----
61 sliderValues <- reactive({
62
63 data.frame(
64 Name = c("Integer",
65 "Decimal",
66 "Range",
67 "Custom Format",
68 "Animation"),
69 Value = as.character(c(input$integer,
70 input$decimal,
71 paste(input$range, collapse = " "),
72 input$format,
73 input$animation)),
74 stringsAsFactors = FALSE)
75
76 })
77
78 # Show the values in an HTML table ----
79 output$values <- renderTable({
80 sliderValues()
81 })
82
83 }
84
85 # Create Shiny app ----
86 shinyApp(ui, server)