Repository navigation
Expand file tree
/
Copy pathapp.R
More file actions
91 lines (81 loc) · 2.63 KB
/
Copy pathapp.R
File metadata and controls
91 lines (81 loc) · 2.63 KB
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
library(shinyvalidate)
library(DT)
myData <- read.csv("./table.csv")
ui <- fluidPage(
includeCSS("styles.css"),
tags$head(tags$link(rel="shortcut icon", type="image/x-icon", href="favicon.ico")),
tags$h1("World's Population stats"),
sidebarLayout(
sidebarPanel(
wellPanel(
sliderInput(inputId = "year",
label="Choose how many years you want to see",
min = 1,
max = 70,
value = 5)
),
wellPanel(
checkboxGroupInput(
inputId = "variables",
label = "Choose the options to display:",
choices = names(myData),
selected = names(myData)
),
submitButton(text = "Apply changes", icon = NULL, width = "100%")
),
wellPanel(
tags$h3("All the data was taken from www.worldometers.info"),
tags$ul(),
tags$li("Year"),
tags$li("World population"),
tags$li("Yearly change (in %)"),
tags$li("Net change (plain number)"),
tags$li("Density ( people per sq.km)"),
tags$li("Urban population"),
tags$li("Per cent of urban population")
)
),
mainPanel(
wellPanel(tags$h3("You are viewing stats for",
textOutput(outputId = "year",
inline = TRUE),
"years"
)
),
wellPanel(
DTOutput("mainTable")
)
)
)
)
server <- function(input, output) {
# checking values for age
observeEvent(input$age, {
inputNum <- input$age
defaultNum <- 5
if(inputNum > 70) {
inputNum <- defaultNum
showNotification( type = "error",
"The number you tried to use exceeds max value of 100,
so default was applied.")
}
if(inputNum < 1) {
inputNum <- defaultNum
showNotification( type = "error",
"The number you tried to use is invalid,
so default was applied.")
}
output$headerAge <- renderText( { inputNum } )
})
reactYearNum <- reactive(input$year)
output$year <- renderText( { input$year } )
output$headerGender <- renderText( { input$gender } )
output$mainTable <- renderDT(
myData[input$variables], options = list(
columnDefs = list(list(className = 'dt-center')),
pageLength = reactYearNum(),
lengthMenu = c(1, 5, 10, 15, 30, 70)
)
)
}
shinyApp(ui = ui, server = server)