-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.R
More file actions
85 lines (74 loc) · 2.69 KB
/
app.R
File metadata and controls
85 lines (74 loc) · 2.69 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
##################################
# Created by EPI-interactive
# 29 Apr 2019
# https://www.epi-interactive.com
##################################
library(shiny)
#Skeleton
createTableSkeleton <- function() {
div(class="skeleton",
div(class="sk-layout sk-layout-column",
div(class="sk-text-row skeleton-item"),
div(class="sk-text-row skeleton-item"),
div(class="sk-text-row skeleton-item"),
div(class="sk-text-row skeleton-item"),
div(class="sk-text-row skeleton-item"),
div(class="sk-text-row skeleton-item"),
div(class="sk-text-row skeleton-item"),
div(class="sk-text-row skeleton-item")
)
)
}
# Basic UI for app
ui <- tagList(
tags$head(
tags$link(rel = "stylesheet", type = "text/css", href = "css/nprogress.css"),
tags$link(rel = "stylesheet", type = "text/css", href = "css/styles.css"),
tags$script(src="js/nprogress.js"),
tags$script(src=("js/main.js"))
),
tags$body(
fluidPage(
div(class="title", h1("Loading and progress")),
div(class="app-body",
div(class="sidebar",
div(
selectInput("sort", "Sort cars by:", c("Horsepower"="hp", "Miles per gallon"="mpg"), "Horsepower"),
selectInput("gears", "Number of gears: ", unique(mtcars$gear), unique(mtcars$gear)[1])
),
tags$img(src="images/Epi_Logo.png", width= "90%")
),
div(class="main",
tableOutput("table"),
createTableSkeleton()
)
)
)
)
)
# Server for app
server <- function(input, output) {
# Simple data for the table - just takes in
appData <- reactive({
req(input$sort, input$gears)
# Wait three seconds to simulate complex calculations
Sys.sleep(3)
# Only select cars data with selected gear number
withGear <- mtcars[mtcars$gear == input$gears, ]
# Sort by chosen sort type
sorted <- withGear[order(withGear[[input$sort]]), ]
#Cleaning up data for table display
sorted$cyl <- as.integer(sorted$cyl)
sorted$hp <- as.integer(sorted$hp)
sorted$gear <- as.integer(sorted$gear)
sorted$carb <- as.integer(sorted$carb)
sorted$vs <- ifelse(sorted$vs == 0,"V-shaped", "Straight")
sorted$am <- ifelse(sorted$am == 0,"Automatic", "Manual")
names(sorted) <- c("Miles/(US) gallon", "Number of cylinders", "Displacement (cu.in.)", "Gross horsepower", "Rear axle ratio", "Weight (1000 lbs)", "1/4 mile time", "Engine", "Transmission", "Number of forward gears", "Number of carburetors")
return(sorted)
})
# Output the table using the data above
output$table <- renderTable(appData())
}
# Run the application
shinyApp(ui = ui, server = server)