forked from plotly/dash-core-components
-
Notifications
You must be signed in to change notification settings - Fork 2
/
dash-info.yaml
798 lines (708 loc) · 26.8 KB
/
dash-info.yaml
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
pkg_help_description: >-
'Dash' ships with supercharged components for
interactive user interfaces. A core set of components,
written and maintained by the 'Dash' team, is available in
the 'dashCoreComponents' package. The source for this package
is on GitHub: plotly/dash-core-components.
pkg_help_title: >-
Core Interactive UI Components for 'Dash'
pkg_authors: >-
c(person("Chris", "Parmer", email = "chris@plotly.com", role = c("aut")), person("Ryan Patrick", "Kyle", email = "ryan@plotly.com", role = c("cre"), comment = c(ORCID = "0000-0002-4958-2844")), person(family = "Plotly Technologies, Inc.", role = "cph"))
pkg_copyright: >-
Plotly Technologies, Inc.
r_examples:
- name: dccChecklist
dontrun: FALSE
code: |
if (interactive() && require(dash)) {
library(dash)
library(dashHtmlComponents)
library(dashCoreComponents)
app <- Dash$new()
app$layout(
dccChecklist(
id = "checklist-input",
options=list(
list("label" = "New York City", "value" = "NYC"),
list("label" = "Montreal", "value" = "MTL"),
list("label" = "San Francisco", "value" = "SF")
),
value=list("MTL", "SF")
)
)
app$run_server()
}
- name: dccInterval
dontrun: FALSE
code: |
if (interactive() && require(dash)) {
library(dash)
library(dashHtmlComponents)
library(dashCoreComponents)
library(plotly)
app <- Dash$new()
app$layout(
htmlDiv(list(
htmlH2('3 Second Updates'),
dccInterval(id = '3s-interval',
interval= 3*1000,
n_intervals = 0),
htmlDiv(list(
dccGraph(id = 'live-graph')
)
)
)
)
)
app$callback(
output = list(
output('live-graph', 'figure')
),
params = list(
input('3s-interval', 'n_intervals')
),
update_graph <- function(n_intervals) {
df <- data.frame(
'time' = c(1:8),
'value' = sample(1:8, 8),
'value-2' = sample(1:8, 8)
)
bar <- animation_opts(plot_ly(
data = df, x=~time, y=~value, type = "bar"),
1000, easing = "cubic-in-out"
)
return(list(bar))
}
)
app$run_server()
}
- name: dccSlider
dontrun: FALSE
code: |
if (interactive() && require(dash)) {
library(dash)
library(dashCoreComponents)
library(dashHtmlComponents)
app <- Dash$new()
app$layout(
htmlDiv(
list(
dccSlider(
id = "slider-input",
min = -5,
max = 10,
step = 0.5,
value = -3
),
htmlDiv(
id = "slider-output",
children = "Make a selection on the slider to see the value appear here."
)
)
)
)
app$callback(
output("slider-output", "children"),
list(input("slider-input", "value")),
function(value) {
return(paste0("You have chosen ", value, " on the slider above."))
}
)
app$run_server()
}
- name: dccConfirmDialog
dontrun: FALSE
code: |
if (interactive() && require(dash)) {
library(dash)
library(dashCoreComponents)
library(dashHtmlComponents)
app <- Dash$new()
app$layout(
htmlDiv(
list(
dccConfirmDialog(
id='confirm',
message='Danger danger! Are you sure you want to continue?'),
dccDropdown(
options=lapply(list('Safe', 'Danger!!'),function(x){list('label'= x, 'value'= x)}),
id='dropdown'
),
htmlDiv(id='output-confirm1')
)
)
)
app$callback(
output = list(id = 'confirm', property = 'displayed'),
params=list(input(id = 'dropdown', property = 'value')),
function(value){
if(value == 'Danger!!'){
return(TRUE)}
else{
return(FALSE)}
})
app$run_server()
}
- name: dccLink
dontrun: FALSE
code: |
if (interactive() && require(dash)) {
library(dash)
library(dashCoreComponents)
library(dashHtmlComponents)
app <- Dash$new()
app$layout(htmlDiv(list(
# represents the URL bar, doesn't render anything
dccLocation(id = 'url', refresh=FALSE),
dccLink('Navigate to "/"', href='/'),
htmlBr(),
dccLink('Navigate to "/page-2"', href='/page-2'),
# content will be rendered in this element
htmlDiv(id='page-content')
)
)
)
app$callback(output=list(id='page-content', property='children'),
params=list(
input(id='url', property='pathname')),
function(pathname) {
paste0('You are on page ', pathname)
}
)
app$run_server()
}
- name: dccStore
dontrun: FALSE
code: |
if (interactive() && require(dash)) {
library(dashCoreComponents)
library(dashHtmlComponents)
library(dash)
app <- Dash$new()
app$layout(htmlDiv(list(
# The memory store reverts to the default on every page refresh
dccStore(id='memory'),
# The local store will take the initial data
# only the first time the page is loaded
# and keep it until it is cleared.
dccStore(id='local', storage_type='local'),
# Same as the local store but will lose the data
# when the browser/tab closes.
dccStore(id='session', storage_type='session'),
htmlTable(list(
htmlThead(list(
htmlTr(htmlTh('Click to store in:', colSpan='3')),
htmlTr(list(
htmlTh(htmlButton('memory', id='memory-button')),
htmlTh(htmlButton('localStorage', id='local-button')),
htmlTh(htmlButton('sessionStorage', id='session-button'))
)),
htmlTr(list(
htmlTh('Memory clicks'),
htmlTh('Local clicks'),
htmlTh('Session clicks')
))
)),
htmlTbody(list(
htmlTr(list(
htmlTd(0, id='memory-clicks'),
htmlTd(0, id='local-clicks'),
htmlTd(0, id='session-clicks')
))
))
))
)))
for (i in c('memory', 'local', 'session')) {
app$callback(
output(id = i, property = 'data'),
params = list(
input(id = paste0(i, '-button'), property = 'n_clicks'),
state(id = i, property = 'data')
),
function(n_clicks, data){
if(is.null(n_clicks)){
return()
}
if(is.null(data[[1]])){
data = list('clicks' = 0)
} else{
data = data
}
data['clicks'] = data$clicks + 1
return(data)
}
)
}
for (i in c('memory', 'local', 'session')) {
app$callback(
output(id = paste0(i, '-clicks'), property = 'children'),
params = list(
input(id = i, property = 'modified_timestamp'),
state(id = i, property = 'data')
),
function(ts, data){
if(is.null(ts)){
return()
}
if(is.null(data[[1]])){
data = list()
} else {
data = data
}
return(data$clicks[[1]])
}
)
}
app$run_server()
}
- name: dccConfirmDialogProvider
dontrun: FALSE
code: |
if (interactive() && require(dash)) {
library(dash)
library(dashCoreComponents)
library(dashHtmlComponents)
app <- Dash$new()
app$layout(htmlDiv(list(
dccConfirmDialogProvider(
children=htmlButton(
'Click Me',
n_clicks = 0
),
id='danger-danger-provider',
message='Danger danger! Are you sure you want to continue?',
submit_n_clicks=NULL
),
htmlDiv(id='output-provider',
children='Click the button to submit')
)))
app$callback(
output = list(id = 'output-provider', property = 'children'),
params=list(input(id = 'danger-danger-provider', property = 'submit_n_clicks')),
function(submit_n_clicks) {
if (is.null(unlist(submit_n_clicks))) {
return('')
} else {
paste0('That was a dangerous choice! Submitted ', submit_n_clicks, ' times.')
}
}
)
app$run_server()
}
- name: dccLoading
dontrun: FALSE
code: |
if (interactive() && require(dash)) {
library(dash)
library(dashCoreComponents)
library(dashHtmlComponents)
app <- Dash$new()
app$layout(htmlDiv(
children=list(
htmlH3("Edit text input to see loading state"),
dccInput(id="input-1", value='Input triggers local spinner'),
dccLoading(id="loading-1", children=list(htmlDiv(id="loading-output-1")), type="default"),
htmlDiv(
list(
dccInput(id="input-2", value='Input triggers nested spinner'),
dccLoading(
id="loading-2",
children=list(htmlDiv(list(htmlDiv(id="loading-output-2")))),
type="circle"
)
)
)
)
))
app$callback(
output = list(id='loading-output-1', property = 'children'),
params = list(input(id = 'input-1', property = 'value')),
function(value){
Sys.sleep(1)
return(value)
}
)
app$callback(
output = list(id='loading-output-2', property = 'children'),
params = list(input(id = 'input-2', property = 'value')),
function(value){
Sys.sleep(1)
return(value)
}
)
app$run_server()
}
- name: dccTab
dontrun: FALSE
code: |
if (interactive() && require(dash)) {
library(dash)
library(dashCoreComponents)
library(dashHtmlComponents)
app <- Dash$new()
app$layout(htmlDiv(list(
dccTabs(id="tabs", value='tab-1', children=list(
dccTab(label='Tab one', value='tab-1'),
dccTab(label='Tab two', value='tab-2')
)
),
htmlDiv(id='tabs-content')
)
)
)
app$callback(output('tabs-content', 'children'),
params = list(input('tabs', 'value')),
function(tab){
if(tab == 'tab-1'){
return(htmlDiv(list(
htmlH3('Tab content 1')
)))}
else if(tab == 'tab-2'){
return(htmlDiv(list(
htmlH3('Tab content 2')
)))}
}
)
app$run_server()
}
- name: dccDatePickerRange
dontrun: FALSE
code: |
if (interactive() && require(dash)) {
library(dash)
library(dashCoreComponents)
app <- Dash$new()
app$layout(
dccDatePickerRange(
id = "date-picker-range",
start_date = as.Date("1997/5/10"),
end_date_placeholder_text="Select a date!"
)
)
app$run_server()
}
- name: dccLocation
dontrun: FALSE
code: |
if (interactive() && require(dash)) {
library(dash)
library(dashCoreComponents)
library(dashHtmlComponents)
app <- Dash$new()
app$layout(htmlDiv(list(
# represents the URL bar, doesn't render anything
dccLocation(id = 'url', refresh=FALSE),
dccLink('Navigate to "/"', href='/'),
htmlBr(),
dccLink('Navigate to "/page-2"', href='/page-2'),
# content will be rendered in this element
htmlDiv(id='page-content')
)
)
)
app$callback(output=list(id='page-content', property='children'),
params=list(
input(id='url', property='pathname')),
function(pathname)
{
paste0('You are on page ', pathname)
}
)
app$run_server()
}
- name: dccTabs
dontrun: FALSE
code: |
if (interactive() && require(dash)) {
library(dash)
library(dashCoreComponents)
library(dashHtmlComponents)
app <- Dash$new()
app$layout(htmlDiv(list(
dccTabs(id="tabs", value='tab-1', children=list(
dccTab(label='Tab one', value='tab-1'),
dccTab(label='Tab two', value='tab-2')
)
),
htmlDiv(id='tabs-content')
)
)
)
app$callback(output('tabs-content', 'children'),
params = list(input('tabs', 'value')),
function(tab){
if(tab == 'tab-1'){
return(htmlDiv(list(
htmlH3('Tab content 1')
)))}
else if(tab == 'tab-2'){
return(htmlDiv(list(
htmlH3('Tab content 2')
)))}
}
)
app$run_server()
}
- name: dccDatePickerSingle
dontrun: FALSE
code: |
if (interactive() && require(dash)) {
library(dash)
library(dashCoreComponents)
app <- Dash$new()
app$layout(
dccDatePickerSingle(
id = "date-picker-single",
date = as.Date("1997/5/10")
)
)
app$run_server()
}
- name: dccLogoutButton
dontrun: FALSE
code: |
if (interactive() && require(dash)) {
library(dash)
library(dashCoreComponents)
app <- Dash$new()
app$layout(
dccLogoutButton(logout_url='/custom-auth/logout')
)
app$run_server()
}
- name: dccTextarea
dontrun: FALSE
code: |
if (interactive() && require(dash)) {
library(dash)
library(dashCoreComponents)
app <- Dash$new()
app$layout(
htmlDiv(
dccTextarea(
placeholder = 'Enter a value...',
value = 'This is a TextArea component'
)
)
)
app$run_server()
}
- name: dccDropdown
dontrun: FALSE
code: |
if (interactive() && require(dash)) {
library(dash)
library(dashCoreComponents)
app <- Dash$new()
app$layout(
htmlDiv(
dccDropdown(
options=list(
list(label = "New York City", value = "NYC"),
list(label = "Montreal", value = "MTL"),
list(label = "San Francisco", value = "SF")
),
value="MTL"
)
)
)
app$run_server()
}
- name: dccMarkdown
dontrun: FALSE
code: |
if (interactive() && require(dash)) {
library(dash)
library(dashHtmlComponents)
library(dashCoreComponents)
app <- Dash$new()
app$title("dccMarkdown Syntax Highlighting Demo")
# dccMarkdown leverages Highlight.js, which allows
# app developers to specify the language inline
# and highlight its syntax properly:
app$layout(
htmlDiv(
list(
htmlDiv(htmlH2("Syntax markdown demo:")),
dccMarkdown(children = "
```r
library(dash)
library(dashHtmlComponents)
app <- Dash$new()
app$layout(htmlDiv('Dash app code wrapped within an app'))
app$run_server()
```")
)
)
)
app$run_server()
}
- name: dccUpload
dontrun: FALSE
code: |
if (interactive() && require(dash)) {
library(dash)
library(dashCoreComponents)
library(dashHtmlComponents)
library(jsonlite)
app <- Dash$new()
app$layout(htmlDiv(list(
dccUpload(
id='upload-image',
children=htmlDiv(list(
'Drag and Drop or ',
htmlA('Select Files')
)),
style=list(
'height'= '60px',
'lineHeight'= '60px',
'borderWidth'= '1px',
'borderStyle'= 'dashed',
'borderRadius'= '5px',
'textAlign'= 'center',
'margin'= '10px'
),
# Allow multiple files to be uploaded
multiple=TRUE
),
htmlDiv(id='output-image-upload')
)))
parse_content = function(contents, filename, date) {
return(htmlDiv(list(
htmlH5(filename),
htmlH6(as.POSIXct(date, origin="1970-01-01")),
htmlImg(src=contents),
htmlHr(),
htmlDiv('Raw Content'),
htmlPre(paste(substr(toJSON(contents), 1, 100), "..."), style=list(
'whiteSpace'= 'pre-wrap',
'wordBreak'= 'break-all'
))
)))
}
app$callback(
output = list(id='output-image-upload', property = 'children'),
params = list(input(id = 'upload-image', property = 'contents'),
state(id = 'upload-image', property = 'filename'),
state(id = 'upload-image', property = 'last_modified')),
function(list_of_contents, list_of_names, list_of_dates) {
if (!is.null(list_of_contents) && !is.null(list_of_names) && !is.null(list_of_dates[[1]])) {
children = lapply(1:length(list_of_contents), function(x){
parse_content(list_of_contents[[x]], list_of_names[[x]], list_of_dates[[x]])
})
}
else {
children = "Upload a file to see the raw data."
}
return(children)
}
)
app$run_server()
}
- name: dccGraph
dontrun: FALSE
code: |
if (interactive() && require(dash)) {
library(dash)
library(dashCoreComponents)
library(plotly)
app <- Dash$new()
year <- c(1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003,
2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012)
worldwide <- c(219, 146, 112, 127, 124, 180, 236, 207, 236, 263,
350, 430, 474, 526, 488, 537, 500, 439)
china <- c(16, 13, 10, 11, 28, 37, 43, 55, 56, 88, 105, 156, 270,
299, 340, 403, 549, 499)
data <- data.frame(year, worldwide, china)
app$layout(
htmlDiv(
dccGraph(
figure = layout(
add_trace(
plot_ly(data,
x = ~year,
y = ~worldwide,
type = "bar",
name = "Worldwide",
marker = list(color = "rgb(55, 83, 109)")
),
y = ~china,
name = "China",
marker = list(color = "rgb(26, 118, 255)")
),
yaxis = list(title = "Count"),
xaxis = list(title = "Year"),
barmode = "group",
title="US Export of Plastic Scrap"),
style = list("height" = 300),
id = "my_graph"
)
)
)
app$run_server()
}
- name: dccRadioItems
dontrun: FALSE
code: |
if (interactive() && require(dash)) {
library(dash)
library(dashHtmlComponents)
library(dashCoreComponents)
app <- Dash$new()
app$layout(
htmlDiv(
dccRadioItems(
options=list(
list("label" = "New York City", "value" = "NYC"),
list("label" = "Montreal", "value" = "MTL"),
list("label" = "San Francisco", "value" = "SF")
),
value = "MTL"
)
)
)
app$run_server()
}
- name: dccInput
dontrun: FALSE
code: |
if (interactive() && require(dash)) {
library(dash)
library(dashHtmlComponents)
library(dashCoreComponents)
app <- Dash$new()
app$layout(
htmlDiv(
dccInput(
placeholder = "Enter a value...",
type = "text",
value = ""
)
)
)
app$run_server()
}
- name: dccRangeSlider
dontrun: FALSE
code: |
if (interactive() && require(dash)) {
library(dash)
library(dashHtmlComponents)
library(dashCoreComponents)
app <- Dash$new()
app$layout(
htmlDiv(
dccRangeSlider(
count = 1,
min = -5,
max = 10,
step = 0.5,
value = list(-3, 7),
marks = as.list(
setNames(-5:10, as.character(-5:10))
)
)
)
)
app$run_server()
}