-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathapp.R
More file actions
1407 lines (1214 loc) · 69.8 KB
/
Copy pathapp.R
File metadata and controls
1407 lines (1214 loc) · 69.8 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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
library(shiny)
library(shinydashboard)
library(ggplot2)
library(plotly)
library(dplyr)
library(fresh)
library(lubridate)
library(tidyverse)
library(viridis)
library(htmltools)
library(scales)
library(leaflet)
library(geosphere)
library(htmlwidgets)
library(dashboardthemes)
library(shinycssloaders)
library(magick)
Sys.setlocale("LC_TIME", "en_US.UTF-8")
#setwd("C:\\Users\\macie\\Desktop\\STUDIA\\SEMESTR3\\Techniki Wizualizacji Danych\\PROJEKTY\\Project2\\MM")
activities_Ola <- read.csv("activities_Ola.csv")
ActivitiesIndividual_Ola <- read.csv("ActivitiesIndividual_Ola.csv")
ActivitiesTogether <- read.csv("ActivitiesTogether_Maciek.csv")
ActivitiesTogether$startTime <- as.POSIXct(ActivitiesTogether$startTime, format = "%Y-%m-%d %H:%M:%S")
ActivitiesTogether$Rok <- format(ActivitiesTogether$startTime, "%Y")
ActivitiesTogether$RokAndMonth <- format(ActivitiesTogether$startTime, "%Y-%m")
ActivitiesTogether$Rok <- as.numeric(ActivitiesTogether$Rok)
ActivitiesTogether$Day <- wday(ActivitiesTogether$startTime, week_start = 1)
ActivitiesTogether$Month <- month(ActivitiesTogether$startTime)
zmienne = c("Distance (km)", "Time (minutes)","Average Speed (km/h)")
zmienne_heat = c("Number of records","Distance (km)","Time (minutes)")
Kroki_Calorie <- read.csv("Kroki_Kalorie_Maciek.csv")
HeartRate_Maciek <- read.csv("HeartRate_Maciek.csv")
HeartRate_Maciek$recordDay <- as.POSIXct(HeartRate_Maciek$recordDay)
# HEADER
# footer = HTML("
# <footer class='text-center text-sm-start' style='width:100%;'>
# <hr>
# <p class='text-center' style='font-size:12px;'>
# © 2024 Copyright:
# <a class='text-dark' href='https://www.mi2.ai/'>MI2</a>
# </p>
# </footer>
# ")
# FOOTERA NIE WIEM W KTORYM MIEJSCU DODAC, JESLI WY WIECIE TO WSTAWCIE.
header <- dashboardHeader(
titleWidth = 300,
title = tags$div(style = "color: white; font-size: 26px; font-family: 'Arial, sans-serif';",
HTML('<img src="https://creazilla-store.fra1.digitaloceanspaces.com/icons/3432125/bike-icon-md.png" style="height:30px; margin-right:10px;">'),
"Our Bike Activity"))
customTheme <- shinyDashboardThemeDIY(
### general
appFontFamily = "Arial"
,appFontColor = "#000000"
,primaryFontColor = "#ffffff"
,bodyBackColor = "#f2f2f2"
### header
,logoBackColor = "#f9a13c"
,headerButtonBackColor = "#394572"
,headerButtonIconColor = "#ffffff"
,headerButtonBackColorHover = "#f9a13c"
,headerButtonIconColorHover = "#ffffff"
,headerBackColor = "#394572"
,headerBoxShadowColor = "#394572"
,headerBoxShadowSize = "12px 2px 2px"
### sidebar
,sidebarBackColor = cssGradientThreeColors(
direction = "down"
,colorStart = "#f9a13c"
,colorMiddle = "#394572"
,colorEnd = "#1f2c5d"
,colorStartPos = 0
,colorMiddlePos = 70
,colorEndPos = 100
)
,sidebarPadding = 0
,sidebarMenuBackColor = "transparent"
,sidebarMenuPadding = 0
,sidebarMenuBorderRadius = 0
,sidebarShadowRadius = "3px 5px 5px"
,sidebarShadowColor = "#aaaaaa"
,sidebarUserTextColor = "rgb(255,255,255)"
,sidebarSearchBackColor = "rgb(55,72,80)"
,sidebarSearchIconColor = "rgb(153,153,153)"
,sidebarSearchBorderColor = "rgb(55,72,80)"
,sidebarTabTextColor = "#ffffff"
,sidebarTabTextSize = 15
,sidebarTabBorderStyle = "none none solid none"
,sidebarTabBorderColor = "#394572"
,sidebarTabBorderWidth = 1
,sidebarTabBackColorSelected = "#394572"
,sidebarTabTextColorSelected = "#ffffff"
,sidebarTabRadiusSelected = "0px 20px 20px 0px"
,sidebarTabBackColorHover = "#394572"
,sidebarTabTextColorHover = "#ffffff"
,sidebarTabBorderStyleHover = "none none solid none"
,sidebarTabBorderColorHover = "#394572"
,sidebarTabBorderWidthHover = 1
,sidebarTabRadiusHover = "0px 20px 20px 0px"
### boxes
,boxBackColor = "#E1E3EC"
,boxBorderRadius = 5
,boxShadowSize = "0px 2px 2px"
,boxShadowColor = "rgba(0,0,0,.1)"
,boxTitleSize = 20
,boxDefaultColor = "#394572"
,boxPrimaryColor = "#394572"
,boxInfoColor = "rgb(210,214,220)"
,boxSuccessColor = "rgba(0,255,213,1)"
,boxWarningColor = "rgb(244,156,104)"
,boxDangerColor = "rgb(255,88,55)"
,tabBoxTabColor = "rgb(255,255,255)"
,tabBoxTabTextSize = 14
,tabBoxTabTextColor = "rgb(0,0,0)"
,tabBoxTabTextColorSelected = "rgb(0,0,0)"
,tabBoxBackColor = "rgb(255,255,255)"
,tabBoxHighlightColor = "rgba(44,222,235,1)"
,tabBoxBorderRadius = 5
### inputs
,buttonBackColor = "rgb(245,245,245)"
,buttonTextColor = "rgb(0,0,0)"
,buttonBorderColor = "rgb(200,200,200)"
,buttonBorderRadius = 5
,buttonBackColorHover = "rgb(235,235,235)"
,buttonTextColorHover = "rgb(100,100,100)"
,buttonBorderColorHover = "rgb(200,200,200)"
,textboxBackColor = "rgb(255,255,255)"
,textboxBorderColor = "rgb(200,200,200)"
,textboxBorderRadius = 5
,textboxBackColorSelect = "rgb(245,245,245)"
,textboxBorderColorSelect = "rgb(200,200,200)"
### tables
,tableBackColor = "rgb(255,255,255)"
,tableBorderColor = "rgb(240,240,240)"
,tableBorderTopSize = 1
,tableBorderRowSize = 1
)
# SIDEBAR
sidebar <- dashboardSidebar(
width = 300,
sidebarMenu(
menuItem("Home", tabName = "home",icon = icon("home")),
menuItem("TOP 5", tabName = "top5", icon = icon("map")),
menuItem("Short/Medium/Long", tabName = "sml", icon = icon("chart-simple")),
menuItem("Competition", tabName = "competition", icon = icon("trophy")),
menuItem("Individual Statistics", tabName = "individualstat", icon = icon('chart-line'), startExpanded = F,
menuSubItem('Maciek', tabName = "individualMaciek", icon = icon('m')),
menuSubItem('Kuba', tabName = "individualKuba", icon = icon("k")),
menuSubItem('Ola', tabName = "individualOla", icon = icon("o"))
)
)
)
# BODY
body <- dashboardBody(
customTheme,
tabItems(
### Kuba ###
tabItem(tabName="home",
#fluidRow(
# uiOutput("homePageDescription")
#),
fluidRow(column(
width=12,
offset=0,
style="text-align: center;",
imageOutput("magickGif")
)),
fluidRow(
column(4, h1("Kuba", align = "center")),
column(4, h1("Maciek", align = "center")),
column(4, h1("Ola", align = "center"))
),
fluidRow(
column(4, img(src = "ikona3-2.png", width = 300, height = 300),style="text-align: center;"),
column(4, img(src = "ikona2-2.png", width = 300, height = 300),style="text-align: center;"),
column(4, img(src = "ikona1-2.png", width = 300, height = 300),style="text-align: center;")
)
),
tabItem(tabName = "top5",
fluidRow(
box(title = "Top 5 tracks", status = "primary", solidHeader = T,
uiOutput("top5description")),
box(status = "primary",
sidebarMenu(id = "sidebarmenuTop5",
selectInput(
inputId = "track",
label = "Choose person:",
choices = c("Kuba", "Maciek", "Ola"))
),
sidebarMenu(id="sidebarmenuTrack",
selectInput(
inputId = "number_of_track",
label = "Choose interesting track:",
choices = c("1","2","3","4","5")))
)),
fluidRow(
box(status = "primary",
shinycssloaders::withSpinner(leafletOutput(outputId = "mapOfTrack",width="100%",height=720),
type = getOption("spinner.type", default = 5),
color = getOption("spinner.color", default = "#394572"),
size = getOption("spinner.size", default = 1)
),width = 12),
box(title="Track description", status = "primary", solidHeader = T,
uiOutput("descriptionOfTrack"),
width = 12)
),
),
tabItem(tabName = "individualKuba",
fluidRow(
box(title = "Individual Statistics", status = "primary", solidHeader = T,
uiOutput("individualTextKuba1"), width = 6),
box(status = "primary", shinycssloaders::withSpinner(plotlyOutput("individualPlotKuba1"),
type = getOption("spinner.type", default = 5),
color = getOption("spinner.color", default = "#394572"),
size = getOption("spinner.size", default = 1)
), width = 6),
box(status = "primary", uiOutput("individualTextKuba2"),
width=12)),
fluidRow(
box(title = "Elevation Data", status = "primary", solidHeader = T,
shinycssloaders::withSpinner(leafletOutput(outputId="individualPlotKuba2",width="100%",height = 720),
type = getOption("spinner.type", default = 5),
color = getOption("spinner.color", default = "#394572"),
size = getOption("spinner.size", default = 1)
),width = 12,
uiOutput("individualTextKuba3"))),
fluidRow(
box(status = "primary",
selectInput("zmienna_heat_Kuba",
"Choose the variable to analyse",
zmienne_heat),
width = 2),
box(title = uiOutput("individualKuba4PlotTitle"), status = "primary", solidHeader = T,
shinycssloaders::withSpinner(plotlyOutput("individualKuba4"),
type = getOption("spinner.type", default = 5),
color = getOption("spinner.color", default = "#394572"),
size = getOption("spinner.size", default = 1)
),
width = 5),
box(title = uiOutput("individualKuba5PlotTitle"), status = "primary", solidHeader = T,
shinycssloaders::withSpinner(plotlyOutput("individualKuba5"),
type = getOption("spinner.type", default = 5),
color = getOption("spinner.color", default = "#394572"),
size = getOption("spinner.size", default = 1)
),
width = 5)
)
),
### Ola ###
tabItem(tabName = "sml",
fluidRow(
box(title = "Small/Medium/Long Tracks", status = "primary", solidHeader = T,
uiOutput("smldescription")),
sidebarMenu(id = "sidebarmenu",
selectInput(
inputId = "person",
label = "Choose person:",
choices = c("Kuba", "Maciek", "Ola"))
)),
fluidRow(
box(title = "What type of routes do we most frequently choose?",
status = "primary", solidHeader = T,
shinycssloaders::withSpinner(plotlyOutput("hisPlot"),
type = getOption("spinner.type", default = 5),
color = getOption("spinner.color", default = "#394572"),
size = getOption("spinner.size", default = 1)
), width = 6),
box(status = "primary",
sliderInput("zakres1",
"Choose the range of years",
value = c(2020, 2023),
min = 2020,
max = 2023,
step = 1),
uiOutput("smlchart1"),
width = 6
)
),
fluidRow(
box(title = "When do we go cycling?", status = "primary", solidHeader = T,
shinycssloaders::withSpinner(plotlyOutput("densityPlot"),
type = getOption("spinner.type", default = 5),
color = getOption("spinner.color", default = "#394572"),
size = getOption("spinner.size", default = 1)
),
uiOutput("smlchart2"), width = 6),
box(title = "Does the length of the route affect our average speed?",
status = "primary", solidHeader = T,
shinycssloaders::withSpinner(plotlyOutput("violinPlot"),
type = getOption("spinner.type", default = 5),
color = getOption("spinner.color", default = "#394572"),
size = getOption("spinner.size", default = 1)
),
uiOutput("smlchart3"), width = 6)
)
),
tabItem(tabName = "individualOla",
fluidRow(
box(title = "Individual Statistics",
status = "primary", solidHeader = T,
uiOutput("individual1"), width = 6),
box(status = "primary",
shinycssloaders::withSpinner(plotlyOutput("individualOla1"),
type = getOption("spinner.type", default = 5),
color = getOption("spinner.color", default = "#394572"),
size = getOption("spinner.size", default = 1)
), width = 6)
),
fluidRow(
box(title = "Analyzing the Diversity of Bike Adventures",
status = "primary", solidHeader = T,
selectInput("yearChoice",
"Activity from which year do your want to see?",
unique(ActivitiesIndividual_Ola$Year)),
shinycssloaders::withSpinner(plotlyOutput("individualOla2"),
type = getOption("spinner.type", default = 5),
color = getOption("spinner.color", default = "#394572"),
size = getOption("spinner.size", default = 1)
),
shinycssloaders::withSpinner(plotlyOutput("individualOla3"),
type = getOption("spinner.type", default = 5),
color = getOption("spinner.color", default = "#394572"),
size = getOption("spinner.size", default = 1)
),
width = 12)
),
fluidRow(
box(status = "primary",
selectInput("zmienna_heat_Ola",
"Choose the variable to analyse",
zmienne_heat),
width = 2),
box(title = uiOutput("individualOla4PlotTitle"), status = "primary", solidHeader = T,
shinycssloaders::withSpinner(plotlyOutput("individualOla4"),
type = getOption("spinner.type", default = 5),
color = getOption("spinner.color", default = "#394572"),
size = getOption("spinner.size", default = 1)
),
width = 5),
box(title = uiOutput("individualOla5PlotTitle"), status = "primary", solidHeader = T,
shinycssloaders::withSpinner(plotlyOutput("individualOla5"),
type = getOption("spinner.type", default = 5),
color = getOption("spinner.color", default = "#394572"),
size = getOption("spinner.size", default = 1)
),
width = 5)
)
),
### Maciek ###
tabItem(tabName = "competition",
fluidRow(
box(
title = "Competiton", status = "primary", solidHeader = T,
uiOutput("competitiondescribtion"),
uiOutput("competitionInteractivityDesc"), width = 6
),
box(
status = "primary", solidHeader = T,
selectInput("zmienna",
"For which variable do you want to summarize?",
zmienne,
),
sliderInput("zakres",
"Choose the range of years",
value = c(min(2020), max(ActivitiesTogether$Rok)),
min = 2020,
max = max(ActivitiesTogether$Rok),
step = 1),
width = 6
)
),
fluidRow(
box(
title = uiOutput("competition1PlotTitle"), status = "primary", solidHeader = T,
shinycssloaders::withSpinner(plotlyOutput("competition1"),
type = getOption("spinner.type", default = 5),
color = getOption("spinner.color", default = "#394572"),
size = getOption("spinner.size", default = 1)
),
width = 6
),
box(
title = "Progression over the years", status = "primary", solidHeader = T,
shinycssloaders::withSpinner(plotlyOutput("competition2"),
type = getOption("spinner.type", default = 5),
color = getOption("spinner.color", default = "#394572"),
size = getOption("spinner.size", default = 1)
)
),
)
),
tabItem(tabName = "individualMaciek",
fluidRow(
box(
uiOutput("individualMaciekdescribtion"),
status = "primary", solidHeader = T
)
),
fluidRow(
box(
status = "primary",
uiOutput("individualMaciek1Desc"),
width = 3
),
box(
title = "Corelation between steps and calories",
status = "primary", solidHeader = T,
numericInput("limitKcal", "Type in calories limit", value=max(Kroki_Calorie$Kalorie)),
shinycssloaders::withSpinner(plotlyOutput("individualMaciek1"),
type = getOption("spinner.type", default = 5),
color = getOption("spinner.color", default = "#394572"),
size = getOption("spinner.size", default = 1)
),
width = 9
)
),
fluidRow(
box(
title = "In which month do I walk the most?",
status = "primary", solidHeader = T,
shinycssloaders::withSpinner(plotlyOutput("individualMaciek2"),
type = getOption("spinner.type", default = 5),
color = getOption("spinner.color", default = "#394572"),
size = getOption("spinner.size", default = 1)
),
width = 6
),
box(
status = "primary",
uiOutput("individualMaciek2Desc"),
width = 6
)
),
fluidRow(
box(uiOutput("individualMaciek3Desc"),
status = "primary",
width = 12
)
),
fluidRow(
box(title = "Average heart rate during exercising per month",
status = "primary", solidHeader = T,
shinycssloaders::withSpinner(plotlyOutput("individualMaciek3"),
type = getOption("spinner.type", default = 5),
color = getOption("spinner.color", default = "#394572"),
size = getOption("spinner.size", default = 1)
),
width = 12
)
),
fluidRow(
box(status = "primary", solidHeader = T,
selectInput("zmienna_heat_Maciek",
"Choose the variable to analyse",
zmienne_heat),
width = 2),
box(title = textOutput("individualMaciek4PlotTitle"),
status = "primary", solidHeader = T,
shinycssloaders::withSpinner(plotlyOutput("individualMaciek4"),
type = getOption("spinner.type", default = 5),
color = getOption("spinner.color", default = "#394572"),
size = getOption("spinner.size", default = 1)
),
width = 5),
box(title = textOutput("individualMaciek5PlotTitle"),
status = "primary", solidHeader = T,
shinycssloaders::withSpinner(plotlyOutput("individualMaciek5"),
type = getOption("spinner.type", default = 5),
color = getOption("spinner.color", default = "#394572"),
size = getOption("spinner.size", default = 1)
),
width = 5)
)
)
## STYLES
# tags$head(
# # # HTML('.main-sidebar { width: 250px; }'),
# # # HTML('.content-wrapper, .right-side { margin-left: 250px; }'),
# # HTML('.main-header .logo { width: 300px }'),
# # HTML('main-header { width: 400px }')
# )
)
)
dashboardPage(header, sidebar, body)
ui <- dashboardPage(header, sidebar, body)
server <- function(input, output) {
output$hisPlot <- renderPlotly({
### Ola ###
activities_Ola$Type <- factor(activities_Ola$Type, levels = c("Short", "Medium", "Long"))
activities_Ola %>%
filter(Osoba == input$person) %>%
group_by(Type) %>%
summarise(n = n()) -> summarizeData
as.numeric(max(summarizeData$n)) -> max_coord
activities_Ola %>%
filter(activities_Ola$Year >= input$zakres1[1],
activities_Ola$Year <= input$zakres1[2]) %>%
filter(Osoba == input$person)-> activities_plot
p <- ggplot(activities_plot, aes(x = Type, fill = Type, text = paste("<br>Number of tracks: ", after_stat(count)))) +
geom_bar(stat = "count") +
scale_fill_manual(values = c("#53296E", "#6B82DB", "#f9a13c")) +
labs(title = "Number of tracks",
x = "Type") +
theme_minimal()+
theme(legend.position = "none", plot.title = element_text(hjust = 0.5),
axis.title.y = element_blank()) +
coord_cartesian(ylim = c(0, max_coord))
ggplotly(p, tooltip = c("text"))
})
output$violinPlot <- renderPlotly({
activities_Ola$Type <- factor(activities_Ola$Type, levels = c("Short", "Medium", "Long"))
activities_Ola %>%
filter(Osoba == input$person)-> activities_plot
p <-ggplot(activities_plot, aes(x = Type, y = as.numeric(AvgSpeed), fill = Type)) +
geom_violin() +
scale_fill_manual(values = c("#53296E", "#6B82DB", "#f9a13c")) +
labs(title = "Distribution of average speed",
x = "Type",
y = "Average Speed") +
theme_minimal()+
theme(legend.position = "none", plot.title = element_text(hjust = 0.5)) +
coord_cartesian(ylim = c(0, 35))
ggplotly(p) %>%
style(hoverinfo = "none")
})
output$densityPlot <- renderPlotly({
activities_Ola$Type <- factor(activities_Ola$Type, levels = c("Short", "Medium", "Long"))
activities_Ola %>%
filter(Osoba == input$person)-> activities_plot
p <- ggplot(activities_plot, aes(x = Hour, fill = Type)) +
geom_density(alpha = 0.75) +
scale_fill_manual(values = c("#53296E", "#6B82DB", "#f9a13c")) +
labs(title = "Density Plot of Activity Distribution Across Hours",
x = "Hour") +
theme_minimal()+
theme(legend.position = "none", plot.title = element_text(hjust = 0.5),
axis.title.y = element_blank())
ggplotly(p) %>%
style(hoverinfo = "none")
})
output$smldescription <- renderUI({
HTML("<div style='text-align: justify;'>
Short/Medium/Long is a tab where our cycling adventure where categorized
according to the distance. A ride spanning 0-40 kilometers is considered
a short track, 40-70 kilometers falls into the medium category, while
anything beyond 70 kilometers is viewed as a long and adventurous expedition.</div>")
})
output$smlchart1 <- renderUI({
HTML("<div style='text-align: justify;'>
Explore our track completion trends with this interactive bar chart.
Categories (short, long, medium) are color-coded, and above slider let
you focus on specific years.Thanks to this chart, we can see our
preferences regarding track length and how they have changed over the years.</div>")
})
output$smlchart2 <- renderUI({
HTML("<div style='text-align: justify;'>
<br>
On the above chart, you can observe the times of day when we embark on
different types of bike rides. It is noticeable that longer cycling
adventures are usually chosen during the morning hours, while shorter
rides tend to take place in the afternoon.</div>")
})
output$smlchart3 <- renderUI({
HTML("<div style='text-align: justify;'>
<br>
On this chart, you can observe the speed distribution categorized by the
type of ride. Surprisingly, the distributions look quite similar. It is
slightly more challenging to maintain a high average speed on longer routes.</div>")
})
# individual
output$individual1 <- renderUI({
HTML("<div style='text-align: justify;'>
Initially, cycling for me was associated with leisurely afternoon rides
with family or friends. I began to view cycling as a sport when I started
riding with my dad, a passionate cycling enthusiast. In the beginning, it was
just to enjoy our time together, but later on, I began tracking my time
and distance, challenging my own records, aiming to ride faster and farther.
The following page is dedicated to more detailed statistics such as speed,
heart rate, pedaling cadence, and riding frequency.<br>
On the right side of the chart, you can observe the correlation between average
speed and pulse. It's evident that for longer distances, the relationship is slightly
higher than for shorter ones, even at comparable average speeds.</div>")
})
output$individualOla1 <- renderPlotly({
p <- ActivitiesIndividual_Ola %>%
filter(Średnie.tętno != 0) %>%
ggplot(aes(x = Średnie.tętno, y = Średnia.prędkość, color = Dystans, size = Dystans, text = paste("Average Pulse: ", Średnie.tętno,
"<br>Average Speed: ", Średnia.prędkość,
"<br>Distance: ", Dystans, "km"))) +
geom_point() +
scale_color_gradient(low = "#ffb663", high = "#7C065C", name = "Distance [km]") +
scale_size_continuous(range = c(1, 4), name = "Distance [km]") +
labs(
title = "Relation between Average Speed and Average Pulse",
x = "Average Pulse",
y = "Average Speed [km/h]"
) +
guides(color = guide_legend(title = "Distance [km]")) +
theme_minimal()+
theme(plot.title = element_text(hjust = 0.5))
ggplotly(p, tooltip = c("text"))
})
output$individualOla2 <- renderPlotly({
ActivitiesIndividual_Ola %>%
filter(ActivitiesIndividual_Ola$Year == 2023) %>%
filter(Średni.rytm.pedałowania != 0 & Średnie.tętno != 0) -> activities_Ola_plot
if(input$yearChoice == 2019){
activities_Ola_plot %>%
filter(Dystans != 8.70) -> activities_Ola_plot
}
activities_Ola_plot$Data <- as.POSIXct(activities_Ola_plot$Data, format = "%Y-%m-%d %H:%M:%S")
activities_Ola_plot %>%
arrange(Data)-> activities_Ola_plot
activities_Ola_plot$Data <- format(activities_Ola_plot$Data, "%d %b")
custom_order <- activities_Ola_plot$Data
activities_Ola_plot$Data <- factor(activities_Ola_plot$Data, levels = custom_order)
plot_ly(
data = activities_Ola_plot,
x = ~Data,
hoverinfo = 'none') %>%
add_trace(y = 140, type = 'scatter', mode = 'lines', line = list(color = '#6D657C', width = 1, dash = 'dash'), showlegend = FALSE, hoverinfo = 'none') %>%
add_trace(y = 160, type = 'scatter', mode = 'lines', line = list(color = '#6D657C', width = 1, dash = 'dash'), showlegend = FALSE, hoverinfo = 'none') %>%
add_trace(y = 150, type = 'scatter', mode = 'lines', line = list(color = "rgba(225, 227, 236, 0.5)", width = 74), name = "Aerobic training area") %>%
add_lines(y = ~Średnie.tętno, name = "Average Pulse", line = list(color = "#ffb663", width = 3),
text = paste("Date: ", activities_Ola_plot$Data, "<br>Distance: ", activities_Ola_plot$Dystans,
"<br>Time: ", activities_Ola_plot$Czas, "<br>Average pulse: ", activities_Ola_plot$Średnie.tętno),
hoverinfo = 'text') %>%
add_lines(y = ~Maksymalne.tętno, name = "Max Pulse", line = list(color = "#7C065C", width = 3),
text = paste("Date: ", activities_Ola_plot$Data, "<br>Distance: ", activities_Ola_plot$Dystans,
"<br>Time: ", activities_Ola_plot$Czas, "<br>Max pulse: ", activities_Ola_plot$Maksymalne.tętno),
hoverinfo = 'text') %>%
layout(title = "Average and Max Pulse",
xaxis = list(title = "Date", tickangle = -60, categoryorder = "array", categoryarray = custom_order),
yaxis = list(title = "Pulse", range = c(125, 185)),
margin = list(t = 70, b =100))
})
output$individualOla3 <- renderPlotly({
ActivitiesIndividual_Ola %>%
filter(ActivitiesIndividual_Ola$Year == input$yearChoice) %>%
filter(Średni.rytm.pedałowania != 0 & Średnie.tętno != 0) -> activities_Ola_plot
if(input$yearChoice == 2019){
activities_Ola_plot %>%
filter(Dystans != 8.70) -> activities_Ola_plot
}
activities_Ola_plot$Data <- as.POSIXct(activities_Ola_plot$Data, format = "%Y-%m-%d %H:%M:%S")
activities_Ola_plot %>%
arrange(Data)-> activities_Ola_plot
activities_Ola_plot$Data <- format(activities_Ola_plot$Data, "%d %b")
custom_order <- activities_Ola_plot$Data
activities_Ola_plot$Data <- factor(activities_Ola_plot$Data, levels = custom_order)
my_color_scale = list(list(0,"#ffb663"),
list(1, "#7C065C"))
plot_ly(
data = activities_Ola_plot,
x = ~as.factor(Data),
hoverinfo = 'none')%>%
add_trace(y = ~Średni.rytm.pedałowania, name = "Average Pedaling Rhythm", type = "bar",
marker = list(color = ~Łącznie.obrotów, colorscale = my_color_scale,
colorbar = list(title = "Total Number of Turns",
len = .6, outlinewidth = 0,
tickfont = list(size = 10)))) %>%
add_lines(y = ~Maksymalny.rytm.pedałowania, name = "Max Pedaling Rhythm", line = list(color = "#7C065C", width = 3),
text = paste("Date: ", activities_Ola_plot$Data, "<br>Distance: ", activities_Ola_plot$Dystans,
"<br>Time: ", activities_Ola_plot$Czas, "<br>Max pedaling rhythm: ", activities_Ola_plot$Maksymalny.rytm.pedałowania,
"<br>Average pedaling rhythm: ", activities_Ola_plot$Średni.rytm.pedałowania),
hoverinfo = "text") %>%
layout(title = "Average and Max Pedaling Rhythm",
xaxis = list(title = "Date", tickangle = -50, categoryorder = "array", categoryarray = custom_order),
yaxis = list(title = "Number of turns per minute"),
margin = list(t = 70, b = 90),
showlegend = TRUE)
})
output$individualOla4 <- renderPlotly({
if(input$zmienna_heat_Ola == "Number of records"){
output$individualOla4PlotTitle <- renderText({"Number of records in each month"})
df <- ActivitiesTogether %>% filter(Rok >=2020, Osoba == "Ola") %>% group_by(Osoba,Month) %>% summarise(score=n())
}
if(input$zmienna_heat_Ola == "Distance (km)"){
output$individualOla4PlotTitle <- renderText({"Distance (km) in each month"})
df <- ActivitiesTogether %>% filter(Rok >=2020, Osoba == "Ola") %>% group_by(Osoba,Month) %>% summarise(score = sum(Dystans))
}
if(input$zmienna_heat_Ola == "Time (minutes)"){
output$individualOla4PlotTitle <- renderText({"Time (minutes) in each month"})
df <- ActivitiesTogether %>% filter(Rok >=2020, Osoba == "Ola") %>% group_by(Osoba,Month) %>% summarise(score = sum(Czas))
}
plot_ly(df,
x=~Month,
y=~score,
type="bar",
hoverinfo = "text",
text = paste("Month: ", month.name[df$Month], paste("<br>",input$zmienna_heat_Ola, ":"), df$score),
textposition = "none",
marker = list(color = "#7C065C")
) %>%
layout(
xaxis = list(title = "Month", tickformat=".d",tickvals = unique(df$Month),
ticktext = month.abb[unique(df$Month)]),
yaxis = list(title=input$zmienna_heat_Ola)
)
})
output$individualOla5 <- renderPlotly({
weekday_names <- c("Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun")
if(input$zmienna_heat_Ola == "Number of records"){
output$individualOla5PlotTitle <- renderText({"Number of records in each day"})
df <- ActivitiesTogether %>% filter(Rok >=2020, Osoba == "Ola") %>% group_by(Osoba,Day) %>% summarise(score=n())
}
if(input$zmienna_heat_Ola == "Distance (km)"){
output$individualOla5PlotTitle <- renderText({"Distance (km) in each day"})
df <- ActivitiesTogether %>% filter(Rok >=2020, Osoba == "Ola") %>% group_by(Osoba,Day) %>% summarise(score = sum(Dystans))
}
if(input$zmienna_heat_Ola == "Time (minutes)"){
output$individualOla5PlotTitle <- renderText({"Time (minutes) in each day"})
df <- ActivitiesTogether %>% filter(Rok >=2020, Osoba == "Ola") %>% group_by(Osoba,Day) %>% summarise(score = sum(Czas))
}
plot_ly(df,
x=~Day,
y=~score,
type="bar",
hoverinfo = "text",
text = paste("Day: ", weekday_names[df$Day], paste("<br>",input$zmienna_heat_Ola, ":"), df$score),
textposition = "none",
marker = list(color = "#7C065C")
) %>%
layout(
xaxis = list(title = "Day", tickformat=".d",tickvals = unique(df$Day),
ticktext = weekday_names[unique(df$Day)]),
yaxis = list(title=input$zmienna_heat_Ola)
)
})
### Kuba ###
gif_path<-"www\\cyclist.gif"
img<-image_read(gif_path)
output$magickGif<-renderImage({
list(src="www/cyclist-3.gif",
contentType = 'image/gif')
},deleteFile = FALSE)
track_info_data <-
activities_Ola[c(74, 23, 54, 49, 2, 253, 169, 276, 109, 275, 307, 314, 319, 316, 318), ]
track_info_data %>% mutate(
choice_type = c(
"Kuba_1",
"Kuba_2",
"Kuba_3",
"Kuba_4",
"Kuba_5",
"Maciek_1",
"Maciek_2",
"Maciek_3",
"Maciek_4",
"Maciek_5",
"Ola_1",
"Ola_2",
"Ola_3",
"Ola_4",
"Ola_5"
),
time_h = DurationMinutes %/% 60,
time_m = floor(DurationMinutes - time_h * 60),
time_s = DurationMinutes * 60 - time_h * 3600 - time_m * 60
) -> track_info_data
output$mapOfTrack <- renderLeaflet(
{
track_selected<-paste(input$track,"_",input$number_of_track,sep="")
df_info_track<-track_info_data %>% filter(choice_type==track_selected)
mydata<-read.csv(paste("Top5_Activities\\activity_",input$track,"_",input$number_of_track,".csv",sep=""))
mydata$ele<-mydata$speed
hotlinePlugin <- htmltools::htmlDependency(
name = 'Leaflet.hotline',
version = "0.4.0",
src = c(file = normalizePath("hotline_plugin")),
script = "leaflet.hotline.js"
)
registerPlugin <- function( map, plugin ) {
map$dependencies <- c( map$dependencies, list( plugin ) )
map
}
palette<- colorNumeric(palette = colorRampPalette(c("#008800","#ffff00","#ff0000"))(5),
domain = 0:40)
mydata %>% group_by(kilometer) %>% slice(tail(which.max(row_number()),1)) -> last_lon_lat_each_km
mydata %>% group_by(kilometer) %>% summarize(mean_speed=mean(speed)) -> avg_speed_per_km
coords_of_kilometers<-last_lon_lat_each_km %>% left_join(avg_speed_per_km,by="kilometer") %>% select(lat,lon,kilometer,mean_speed)
paste("Kilometer: ","<strong>",coords_of_kilometers$kilometer,"</strong>","<br>Average speed: ","<strong>",round(coords_of_kilometers$mean_speed,2),"</strong>",sep="") %>%
lapply(htmltools::HTML) -> labels
map_with_colors<-leaflet() %>% addTiles() %>%
fitBounds( min(mydata$lon), min(mydata$lat), max(mydata$lon), max(mydata$lat) ) %>%
registerPlugin(hotlinePlugin) %>%
onRender("function(el, x, data) {
data = HTMLWidgets.dataframeToD3(data);
data = data.map(function(val) { return [val.lat, val.lon, val.ele]; });
L.hotline(data, {min: 0, max: 40}).addTo(this);
}", data = mydata ) %>% addLegend("bottomright",pal=palette,values=0:40,opacity=1,title="Speed [km/h]") %>%
addCircleMarkers(data=coords_of_kilometers,lat=~lat,lng=~lon,label=~labels,fillColor="#405CB9",fillOpacity=1,stroke=F,radius=6)
# map_with_colors %>% onRender(
# "
# function(el, x, df_info_track) {
# var info = L.control();
#
# info.onAdd = function(map) {
# this._div = L.DomUtil.create('div', 'info-box'); // tworzymy div z klasą 'info-box'
# this.update();
# return this._div;
# };
#
# info.update = function(df) {
# var currentData = HTMLWidgets.dataframeToD3(df); // Zakładam, że dane są jednolite na mapie
#
# this._div.innerHTML = '<h4>Informacje</h4>' +
# '<p>Data: ' + currentData.Date + '</p>' +
# '<p>Dystans: ' + currentData.Distance + ' km</p>' +
# '<p>Czas: ' + currentData.DurationMinutes + ' minut</p>' +
# '<p>Średnia prędkość: ' + currentData.AvgSpeed + ' km/h</p>';
# };
#
# info.addTo(this);
# }
# ",df=df_info_track)
}
)
output$homePageDescription<-renderUI({HTML("<div style='text-align: justify; font-size: 18px; margin: 20px;'>I have been planning this trip with my bike comrade Michał for a year.
We couldn’t find the time for it, but finally on the last day of summer holidays, on 31.08.2021 we managed to realize our “dream”. Until we reached Warka, we didn’t have much difficulties.
The troubles began after leaving the city. We did not know the route perfectly and even with GPS we had difficulties. We landed in forest two times, the road surface was terrible, we were moving with really low speed.
But in the end, we reached our destination. We didn’t have time to stay there, as the departure time of train was near.</div>")
})
output$top5description <- renderUI({
HTML("<div style='text-align: justify;'>Explore our most interesting tracks. The map consists track route, which is coloured in various colors.
Each color represents respective speed. Shades of green are used for presenting lower speeds, such as 0 km/h or 10 km/h.
Yellow and green color mixtures represent values of speed in range from 10 km/h to 20km/h. Yellow color corresponds to the value of 20km/h,
red stands for every speed that is equal to 40 km/h or greater than it. Shades of mixed yellow and red are for values between 20 km/h and 40 km/h.</div>")
})
output$descriptionOfTrack <- renderUI({
text_Kuba_1<-HTML("<div style='text-align: justify;'>Monday, 5th of September 2022 at first glance did not seem to become a day, when I set my longest bike trip.
The starting time of the ride did not indicate that it would be one of the most amazing trips.
I messaged my friend Michał, and we met each other on the Most Południowy at 1:00 PM. We planned to reach our beloved Góra Kalwaria and then decide what to do next.
Everything went as planned, we also had a decent average speed, the weather was fantastic, so we decided to extend our ride and go to Warka.
We have been there quite a few times, but the road to Warka is always really demanding. There are a lot of trucks, so you have to keep the pace and be really cautious.
It wasn’t easy at all, but we have made to the city. We stayed there for a several minutes, chilled a little bit, and then started coming back. The route to Warsaw was completed without any major obstacles.
We had a really good average speed, I was feeling that my muscles aren’t that tired, so I have decided to extend the ride in Warsaw.
I managed to do extra 50 kilometres, I was extremely exhausted, but also very happy of this achievement.</div>")
text_Kuba_2<-HTML("<div style='text-align: justify;'>I have been planning this trip with my bike comrade Michał for a year.
We couldn’t find the time for it, but finally on the last day of summer holidays, on 31.08.2021 we managed to realize our “dream”. Until we reached Warka, we didn’t have much difficulties.
The troubles began after leaving the city. We did not know the route perfectly and even with GPS we had difficulties. We landed in forest two times, the road surface was terrible, we were moving with really low speed.
But in the end, we reached our destination. We didn’t have time to stay there, as the departure time of train was near.</div>")
text_Kuba_3<-HTML("<div style='text-align: justify;'>The route to Warka on June 22nd 2022 was another trip to our liked place.
We started cycling around 10:00 AM. The weather was quite bearable, there was around 22°C. The trip was mostly peaceful. We did not have any troubles and difficulties.
We stayed and chilled in Warka for some time and managed to comeback to Warsaw without any unexpected adventures. In the meantime we had a stop at our favourite grocery shop in Góra Kalwaria.
We recharged our batteries and rode with quite good pace to our final destination.</div>")
text_Kuba_4<-HTML("<div style='text-align: justify;'>This trip was the only one from considered routes, that I rode alone. It was just an ordinary trip do Góra Kalwaria. However I did it on Sunday, which was actually quite surprising, because I usually don’t go cycling on that day.
I felt power on that day, as the average speed shows – 26,2 km/h. I did the first part in less than hour, I felt huge exhaust, so the second part was much more difficult.