This repository has been archived by the owner on Sep 12, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.R
787 lines (726 loc) · 24 KB
/
app.R
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
library(dash)
library(dashCoreComponents)
library(dashHtmlComponents)
library(dashBootstrapComponents)
library(readr)
library(ggplot2)
library(plotly)
library(dplyr)
plotly::ggplotly
app <- Dash$new(external_stylesheets = dbcThemes$BOOTSTRAP)
#Read data
structure <- read_csv("data/raw_data/structure.csv")
price <- read_csv("data/processed_data/price.csv")
price_OHLC <- select(price, Open,High,Low,Close,Name,New_date1,RollingAvg7_Close)
price_rest <- subset(price, Name != 'bitcoin' & Name != 'bitcoin_cash')
#Manipulate data on the go
structure_bitcoin <- structure[structure$Name == 'bitcoin',]
structure_rest <- structure[structure$Name != 'bitcoin',]
#Creating variables are needed
structure_rest_name <- structure_rest$Name
# Individual tab content
tab1_content =
dbcContainer(
list(
# Row about all Open USD, Close USD etc
dbcRow(
list(
dbcCol(
list(
htmlH5('')
)
),
dbcCol(
list(
htmlH5('Open Val (USD)')
)
),
dbcCol(
list(
htmlH5('Close Val (USD)')
)
),
dbcCol(
list(
htmlH5('Average L7 (USD)')
)
),
dbcCol(
list(
htmlH5('Average L30 (USD)')
)
),
dbcCol(
list(
htmlH5('Market Cap (Billion USD)')
)
),
dbcCol(
list(
htmlH5('Volume (Million)')
)
)
), style = list('text-align' = 'center', 'color' = '#d4af37')
),
# Row about all definations
dbcRow(
list(
dbcCol(
list(
htmlH6('')
)
),
dbcCol(
list(
htmlP('Opening price on the latest day')
)
),
dbcCol(
list(
htmlP('Closing price on the latest day')
)
),
dbcCol(
list(
htmlP('Average price of the last 7 days')
)
),
dbcCol(
list(
htmlP('Average price of the last 30 days')
)
),
dbcCol(
list(
htmlP('Market capitalization')
)
),
dbcCol(
list(
htmlP('Transaction on the lastest day')
)
)
), style = list('text-align' = 'center', 'color' = 'white')
),
# Row about values of bitcoin
dbcRow(
list(
dbcCol(
list(
htmlH6('Bitcoin')
)
),
dbcCol(
list(
htmlH6(structure_bitcoin$LatestOpen)
)
),
dbcCol(
list(
htmlH6(structure_bitcoin$LatestClose)
)
),
dbcCol(
list(
htmlH6(structure_bitcoin$L7D)
)
),
dbcCol(
list(
htmlH6(structure_bitcoin$L30D)
)
),
dbcCol(
list(
htmlH6(structure_bitcoin$LatestMarketCap_inB)
)
),
dbcCol(
list(
htmlH6(structure_bitcoin$LatestVolume_inM)
)
)
), style = list('text-align' = 'center', 'color' = '#B3D0C9')
),
# Row about values of rest of the currencies || Need to work on dropdown and respective values
dbcRow(
list(
dbcCol(
list(
dccDropdown(
id='currencylist',
options = structure_rest$Name %>% purrr::map(function(col) list(label = col, value = col)),
value='ethereum')
)
),
dbcCol(
list(
htmlH6(id='Open')
)
),
dbcCol(
list(
htmlH6(id='Close')
)
),
dbcCol(
list(
htmlH6(id="L7D")
)
),
dbcCol(
list(
htmlH6(id="L30D")
)
),
dbcCol(
list(
htmlH6(id="MarketCap")
)
),
dbcCol(
list(
htmlH6(id="Volume")
)
)
), style = list('text-align' = 'center', 'color' = 'pink')
),
dbcRow(
list(
dbcCol(
list(
htmlBr()
)
)
)
),
dbcRow(
list(
dbcCol(
list(
htmlBr()
)
)
)
),
dbcRow(
list(
dbcCol(
list(
htmlH2("Volume of all cryptocurrencies"
)
)
)
), style = list('text-align' = 'center', 'color' = '#d4af37')
),
dbcRow(
list(
dbcCol(
list(
dccGraph(id='vol1',style=list("height"=400))
)
)
)
),
dbcRow(
list(
dbcCol(
list(
#dccGraph(id='time-series1')
)
)
)
)
)
)
tab2_content =
dbcContainer(
list(
dbcRow(
list(
dbcCol(
list(
dccDropdown(id='OHLC',
options = list(list(label = "Open : Opening price on the given day", value = "Open"),
list(label = "High : Highest price on the given day", value = "High"),
list(label = "Low : Lowest price on the given day", value = "Low"),
list(label = "Close : Closing price on the given day", value = "Close")),
value = 'Close'
),
htmlBr()
)
)
), style = list('text-align' = 'center', 'color' = 'purple')
),
dbcRow(
list(
dbcCol(
list(
dccGraph(id='group1',
style=list("height"=800))
)
)
)
)
)
)
tab3_content =
dbcContainer(
list(
dbcRow(
list(
dbcCol(
list(
htmlH2("Box Plot of all the cryptocurrencies"),
dccGraph(id="quartile1",
style=list("height"=400))
)
)
)
),
dbcRow(
list(
dbcCol(
list(htmlBr(),
htmlH2("Market Capitalization of all the cryptocurrencies"),
dccGraph(id="hist1",
style=list("height"=400))
)
)
)
)
)
)
tab4_content =
dbcContainer(
list(
dbcRow(
list(
dbcCol(
list(
htmlBr()
)
)
)
),
dbcRow(
list(
dbcCol(
list(
htmlBr()
)
)
)
),
dbcRow(
list(
dbcCol(
list(
htmlBr()
)
)
)
),
dbcRow(
list(
dbcCol(
list(
htmlBr()
)
)
)
),
dbcRow(
list(
dbcCol(
list(
htmlBr()
)
)
)
),
dbcRow(
list(
dbcCol(
list(
htmlH1("Buy and Sell cryptocurrency"),
htmlBr(),
htmlBr(),
htmlBr(),
htmlH4("Fast and secure way to purchase or exchange cryptocurrencies"),
htmlBr(),
htmlBr(),
htmlBr(),
dbcRow(
list(
dbcCol(
list(
dbcInput(placeholder="Subscribe now...", type="text")
)
),
dbcCol(
list(
dbcButton("→", color="light", className="mr-1")
)
)
)
),
htmlBr(),
htmlBr(),
htmlBr(),
htmlBr(),
htmlBr(),
htmlBr(),
htmlBr(),
htmlBr()
), style = list('text-align' = 'left')
),
dbcCol(
list(
htmlH3("Send"),
dccDropdown(
id="moderncurrency",
#"USD", "EUR", "GBP", "YEN", "INR", "CAD", "SGD"
options = list(list(label = "US Dollar", value = "USD"),
list(label = "Canadian Dollar", value = "CAD"),
list(label = "Euro", value = "EUR"),
list(label = "Pound Sterling", value = "GBP"),
list(label = "Singapore Dollar", value = "SGD"),
list(label = "Japanese Yen", value = "YEN"),
list(label = "Indian Rupees", value = "INR")),
value = 'CAD'
),
htmlBr(),
dccInput(id="moderncurrency1",type='number', placeholder=0),
htmlBr(),
htmlBr(),
htmlBr(),
htmlH3("Receive"),
#"bitcoin", "dash", "bitcoin_cash", "bitconnect", "ethereum", "iota", "litecoin",
#"monero", "nem", "neo", "numeraire", "omisego", "qtum", "ripple", "stratis", "waves"
dccDropdown(
id="crypto",
options = list(list(label = "bitcoin", value = "bitcoin"),
list(label = "dash", value = "dash"),
list(label = "bitcoin_cash", value = "bitcoin_cash"),
list(label = "bitconnect", value = "bitconnect"),
list(label = "ethereum", value = "ethereum"),
list(label = "ethereum_classic", value = "ethereum_classic"),
list(label = "iota", value = "iota"),
list(label = "litecoin", value = "litecoin"),
list(label = "monero", value = "monero"),
list(label = "nem", value = "nem"),
list(label = "neo", value = "neo"),
list(label = "numeraire", value = "numeraire"),
list(label = "omisego", value = "omisego"),
list(label = "qtum", value = "qtum"),
list(label = "ripple", value = "ripple"),
list(label = "stratis", value = "stratis"),
list(label = "waves", value = "waves")),
value = 'dash'
),
htmlBr(),
htmlDiv(id='crypto1'),
dbcButton("Buy now", color="light", className="mr-1")
), style = list('text-align' = 'left')
)
)
)
)
)
tab5_content =
dbcContainer(
list(
dbcRow(
list(
dbcCol(
list(
htmlBr(),
htmlBr(),
htmlBr(),
htmlBr(),
htmlBr(),
htmlH4("Email"),
htmlBr(),
dccInput(type="email", id="email1", placeholder="[email protected]"),
htmlBr(),
htmlBr(),
htmlBr(),
htmlH4("Password"),
htmlBr(),
dccInput(type="password", id="password1", placeholder="Enter password"),
htmlBr(),
htmlBr(),
dbcButton("Login", color="light", className="mr-1"),
htmlBr(),
htmlBr(),
htmlBr(),
htmlP("If you are a new user then click below to register"),
dbcButton("Register", color="light", className="mr-1"),
htmlBr(),
htmlBr(),
htmlBr(),
htmlBr(),
htmlBr(),
htmlBr(),
htmlBr()
))
)
)
)
)
tab6_content =
dbcContainer(
list(
dbcRow(
list(
dbcCol(
list(
htmlH2("What is cryptocurrency"),
htmlBr()
)
)
)
),
dbcRow(
list(
dbcCol(
list(
htmlP('Cryptocurrency is digital money. That means there’s no physical coin or bill — it’s all online. You can transfer cryptocurrency to someone online without a go-between, like a bank. Bitcoin and Ether are well-known cryptocurrencies, but new cryptocurrencies continue to be created.'),
htmlBr(),
htmlP('People might use cryptocurrencies for quick payments and to avoid transaction fees. Some might get cryptocurrencies as an investment, hoping the value goes up. You can buy cryptocurrency with a credit card or, in some cases, get it through a process called “mining.” Cryptocurrency is stored in a digital wallet, either online, on your computer, or on other hardware.'),
htmlBr(),
htmlP('Before you buy cryptocurrency, know that it does not have the same protections as when you are using U.S. dollars. Also know that scammers are asking people to pay with cryptocurrency because they know that such payments are typically not reversible.'),
htmlBr(),
htmlBr()
), style = list('color' = 'white')
)#,style = list('color' = 'white')
)
),
dbcRow(
list(
dbcCol(
list(
htmlH2("Cryptocurrencies vs. U.S. Dollars"),
htmlBr()
)
)
)
),
dbcRow(
list(
dbcCol(
list(
htmlP('The fact that cryptocurrencies are digital is not the only important difference between cryptocurrencies and traditional currencies like U.S. dollars.'),
htmlBr()
), style = list('color' = 'white')
)#,style = list('color' = 'white')
)
),
dbcRow(
list(
dbcCol(
list(htmlH4('Cryptocurrencies aren’t backed by a government.'),
htmlBr()
)
)
)
),
dbcRow(
list(
dbcCol(
list(
htmlP('Cryptocurrencies are not insured by the government like U.S. bank deposits are. This means that cryptocurrency stored online does not have the same protections as money in a bank account. If you store your cryptocurrency in a digital wallet provided by a company, and the company goes out of business or is hacked, the government may not be able to step and help get your money back as it would with money stored in banks or credit unions.'),
htmlBr()
), style = list('color' = 'white')
)#,style = list('color' = 'white')
)
),
dbcRow(
list(
dbcCol(
list(htmlH4('A cryptocurrency’s value changes constantly.'),
htmlBr()
)
)
)
),
dbcRow(
list(
dbcCol(
list(
htmlP('A cryptocurrency’s value can change by the hour. An investment that may be worth thousands of U.S. dollars today might be worth only hundreds tomorrow. If the value goes down, there’s no guarantee that it will go up again.'),
htmlBr()
), style = list('color' = 'white')
)
)
)
),style = list('color' = '#d4af37', 'background' = "#1C232F", 'text-align' = 'left')
)
# all tabs content
tabs = htmlDiv(
list(
htmlH2("Cryptocurrency Reporting Dashboard"),
dbcTabs(
list(
dbcTab(children=list(
htmlBr(),
tab6_content
),
label="About Cryptocurrency"
),dbcTab(children=list(
htmlBr(),
tab1_content
),
label="Overview"
),
dbcTab(children=list(
htmlBr(),
tab2_content
),
label="DeepDive-1"
),
dbcTab(children=list(
htmlBr(),
tab3_content
),
label="DeepDive-2"
),
dbcTab(children=list(
htmlBr(),
tab4_content
),
label="Buy & Sell"
),
dbcTab(children=list(
htmlBr(),
tab5_content
),
label="My Account"
)
)
)
),style = list('color' = '#d4af37', 'background' = "#1C232F", 'text-align' = 'center')
)
# final layout
app$layout(
dbcContainer(
list(
htmlBr(),
tabs
)
)
)
# Call back
app$callback(
output('vol1', 'figure'), #dccGraphID
list(input('currencylist', 'value')), #dccDropdownID
function(xcol) {
price_x <- subset(price, Name == 'bitcoin' | Name == xcol) # Should we change the below graph to adjust the source?
p1 <- ggplot(price) +
aes(x = New_date1,
y = Volume/1000000,
color = Name,
fill = Name) +
geom_smooth() + ylab("Volume in millions")
px1 <- p1 + theme(axis.title.x = element_blank())
return(ggplotly(px1))
}
)
app$callback(
output('group1', 'figure'), #dccGraphID
list(input('OHLC', 'value')), #dccDropdownID
function(ycol) {
options(repr.plot.width = 10, repr.plot.height = 300)
p2 <- ggplot(price_OHLC, aes(x = New_date1, y = !!sym(ycol), col = Name)) + geom_line() + ggthemes::scale_fill_tableau()
px2 <- p2 + facet_wrap(~Name, scales = "free", ncol = 3) + theme_minimal() + theme(legend.position="none") + ylab("Price (USD)")
return(ggplotly(px2))
}
)
app$callback(
output('hist1', 'figure'), #dccGraphID
list(input('OHLC', 'value')), #dccDropdownID
function(ycol) {
options(repr.plot.width = 10, repr.plot.height = 300)
p5 <- ggplot(price_rest, aes(New_date1, RollingAvg7_Close, color=Name)) + geom_line()
px5 <- p5 + theme(axis.title.x = element_blank()) + ylab("Rolling Avg of 7 Days")
return(ggplotly(px5))
}
)
app$callback(
output('quartile1', 'figure'), #dccGraphID
list(input('OHLC', 'value')), #dccDropdownID
function(ycol) {
options(repr.plot.width = 10, repr.plot.height = 300)
p3 <- ggplot(price_rest, aes(Name, RollingAvg7_Close, color=Name)) + geom_point() + geom_boxplot() + ggthemes::scale_fill_tableau()
px3 <- p3 + theme_minimal() + theme(legend.position="none") + ylab("Rolling Avg of 7 Days")
return(ggplotly(px3))
}
)
app$callback(
output('crypto1', 'children'), #dccGraphID
list(input('moderncurrency1', 'value'),
input('moderncurrency', 'value'),
input('crypto', 'value')), #dccDropdownID
function(moderncurrency1, moderncurrency, crypto){
values <- c(1.0, 0.84, 0.72, 109.04, 72.53, 1.24, 1.34, 0.000017, 0.0048253, 0.0020147, 0.1984127, 0.0006391, 0.7633588, 00054969, 0.0049655, 1.333333, 0.0267165, 0.0252717, 0.1776199, 0.157779, 2.1276596, 1.0869565, 0.102146 ) #Moderen currency (to currency)
names(values) <- c("USD", "EUR", "GBP", "YEN", "INR", "CAD", "SGD", "bitcoin", "dash", "bitcoin_cash", "bitconnect", "ethereum", "iota", "litecoin", "monero", "nem", "neo", "numeraire", "omisego", "qtum", "ripple", "stratis", "waves") #Moderen currency name (to currency name)
v1 = round((values[crypto]/values[moderncurrency])/moderncurrency1,5)
return(v1)
}
)
app$callback(
list(output('Open','children')),
list(input('currencylist','value')),
function(xcol) {
structure_rest_z1 <- subset(structure_rest, Name == xcol)
z1 <- structure_rest_z1$LatestOpen
return(list(z1))
}
)
app$callback(
list(output('Close','children')),
list(input('currencylist','value')),
function(xcol) {
structure_rest_z2 <- subset(structure_rest, Name == xcol)
z2 <- structure_rest_z2$LatestClose
return(list(z2))
}
)
app$callback(
list(output('L7D','children')),
list(input('currencylist','value')),
function(xcol) {
structure_rest_z3 <- subset(structure_rest, Name == xcol)
z3 <- structure_rest_z3$L7D
return(list(z3))
}
)
app$callback(
list(output('L30D','children')),
list(input('currencylist','value')),
function(xcol) {
structure_rest_z4 <- subset(structure_rest, Name == xcol)
z4 <- structure_rest_z4$L30D
return(list(z4))
}
)
app$callback(
list(output('MarketCap','children')),
list(input('currencylist','value')),
function(xcol) {
structure_rest_z5 <- subset(structure_rest, Name == xcol)
z5 <- structure_rest_z5$LatestMarketCap_inB
return(list(z5))
}
)
app$callback(
list(output('Volume','children')),
list(input('currencylist','value')),
function(xcol) {
structure_rest_z6 <- subset(structure_rest, Name == xcol)
z6 <- structure_rest_z6$LatestVolume_inM
return(list(z6))
}
)
app$run_server(host = '0.0.0.0')