jofaichow commited on
Commit
2ea45d7
1 Parent(s): 5842855

0.1.4 - experimental features in model performance

Browse files
Files changed (2) hide show
  1. Dockerfile +1 -1
  2. app/app.R +104 -7
Dockerfile CHANGED
@@ -8,7 +8,7 @@ RUN R -q -e "install.packages(c('shinydashboard', 'shinydashboardPlus'))"
8
  RUN R -q -e "install.packages(c('shinyWidgets', 'shinycssloaders'))"
9
 
10
  # other R packages
11
- RUN R -q -e "install.packages(c('DT', 'plotly', 'scico', 'ggthemes', 'scales'))"
12
  RUN R -q -e "install.packages(c('data.table', 'dtplyr', 'parallel', 'Rnumerai'))"
13
 
14
  # copy the app to the image
 
8
  RUN R -q -e "install.packages(c('shinyWidgets', 'shinycssloaders'))"
9
 
10
  # other R packages
11
+ RUN R -q -e "install.packages(c('DT', 'plotly', 'scico', 'ggthemes', 'scales', 'wesanderson'))"
12
  RUN R -q -e "install.packages(c('data.table', 'dtplyr', 'parallel', 'Rnumerai'))"
13
 
14
  # copy the app to the image
app/app.R CHANGED
@@ -9,6 +9,8 @@ library(plotly)
9
  library(scico)
10
  library(ggthemes)
11
  library(scales)
 
 
12
 
13
  library(data.table)
14
  library(dtplyr)
@@ -76,6 +78,28 @@ reformat_data <- function(d_raw) {
76
 
77
  }
78
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
79
 
80
  # ==============================================================================
81
  # UI
@@ -317,8 +341,23 @@ ui <- shinydashboardPlus::dashboardPage(
317
 
318
  tabItem(tabName = "performance",
319
  fluidPage(
320
- markdown("![image](https://media.giphy.com/media/cftSzNoCTfSyAWctcl/giphy.gif)")
321
- )
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
322
  ),
323
 
324
 
@@ -339,7 +378,7 @@ ui <- shinydashboardPlus::dashboardPage(
339
  icon = icon("cloud-download"),
340
  style = "gradient",
341
  block = T)
342
- )
343
  )
344
  ),
345
 
@@ -349,6 +388,9 @@ ui <- shinydashboardPlus::dashboardPage(
349
  # ========================================================================
350
 
351
  tabItem(tabName = "about",
 
 
 
352
  markdown("# **About this App**"),
353
  markdown('### Yet another Numerai community dashboard by <b><a href="https://linktr.ee/jofaichow" target="_blank">Jo-fai Chow</a></b>.'),
354
 
@@ -365,6 +407,7 @@ ui <- shinydashboardPlus::dashboardPage(
365
  - #### **0.1.1** — Added a functional `Payout Summary` page
366
  - #### **0.1.2** — `Payout Summary` layout updates
367
  - #### **0.1.3** — Added `Raw Data`
 
368
  "),
369
 
370
  br(),
@@ -383,7 +426,7 @@ ui <- shinydashboardPlus::dashboardPage(
383
 
384
  footer = shinydashboardPlus::dashboardFooter(
385
  left = "Powered by ❤️, ☕, Shiny, and 🤗 Spaces",
386
- right = paste0("Version 0.1.3"))
387
 
388
  )
389
 
@@ -664,8 +707,7 @@ server <- function(input, output) {
664
  "\nPayout:", round(payout,2), "NMR"))) +
665
  geom_bar(stat = "identity") +
666
  theme(
667
- panel.border = element_rect(fill = 'transparent',
668
- color = "grey", linewidth = 0.25),
669
  panel.background = element_rect(fill = 'transparent'),
670
  plot.background = element_rect(fill = 'transparent', color = NA),
671
  panel.grid.major = element_blank(),
@@ -737,7 +779,7 @@ server <- function(input, output) {
737
  formatRound(columns = c("total_stake", "net_payout", "rate_of_return"), digits = 2) |>
738
 
739
  formatStyle(columns = c("round"), fontWeight = "bold") |>
740
-
741
  formatStyle(columns = c("resolved"),
742
  target = "row",
743
  backgroundColor = styleEqual(c(1,0), c("transparent", "#FFF8E1"))) |>
@@ -760,6 +802,61 @@ server <- function(input, output) {
760
  })
761
 
762
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
763
  # ============================================================================
764
  # Reactive: Downloads
765
  # ============================================================================
 
9
  library(scico)
10
  library(ggthemes)
11
  library(scales)
12
+ library(stringr)
13
+ library(wesanderson)
14
 
15
  library(data.table)
16
  library(dtplyr)
 
78
 
79
  }
80
 
81
+ # Generate Colour Palette
82
+ gen_custom_palette <- function(ls_model) {
83
+
84
+ # Extract info
85
+ n_limit <- 5
86
+ n_coluor <- length(unique(ls_model))
87
+ n_pal_rep <- ceiling(n_coluor / n_limit)
88
+ wes_pal_themes <- rep(c("Cavalcanti1", "Darjeeling1"), n_pal_rep)
89
+
90
+ # Generate
91
+ custom_palette <- c()
92
+ for (n_pal in 1:n_pal_rep) {
93
+ tmp_pal_name <- wes_pal_themes[n_pal]
94
+ tmp_pal <- wesanderson::wes_palette(name = tmp_pal_name, n = n_limit, type = "continuous")
95
+ custom_palette <- c(custom_palette, tmp_pal)
96
+ }
97
+
98
+ # Trim and return
99
+ return(custom_palette[1:n_coluor])
100
+
101
+ }
102
+
103
 
104
  # ==============================================================================
105
  # UI
 
341
 
342
  tabItem(tabName = "performance",
343
  fluidPage(
344
+
345
+ markdown("# **Model Performance**"),
346
+ markdown("### **Note 1**: Experimental features. Changes to be expected in the coming days."),
347
+ markdown("### **Note 2**: Define the range in `Payout Summary` first."),
348
+ br(),
349
+
350
+ tabsetPanel(type = "tabs",
351
+ tabPanel("Boxplot - TCP",
352
+ br(),
353
+ markdown("### **TC Percentile by Model**"),
354
+ shinycssloaders::withSpinner(plotlyOutput("plot_boxplot_tcp"))
355
+ )
356
+
357
+ ) # End of tabsetPanel
358
+
359
+ ) # End of fluidPage
360
+
361
  ),
362
 
363
 
 
378
  icon = icon("cloud-download"),
379
  style = "gradient",
380
  block = T)
381
+ )
382
  )
383
  ),
384
 
 
388
  # ========================================================================
389
 
390
  tabItem(tabName = "about",
391
+
392
+ # markdown("![image](https://media.giphy.com/media/cftSzNoCTfSyAWctcl/giphy.gif)")
393
+
394
  markdown("# **About this App**"),
395
  markdown('### Yet another Numerai community dashboard by <b><a href="https://linktr.ee/jofaichow" target="_blank">Jo-fai Chow</a></b>.'),
396
 
 
407
  - #### **0.1.1** — Added a functional `Payout Summary` page
408
  - #### **0.1.2** — `Payout Summary` layout updates
409
  - #### **0.1.3** — Added `Raw Data`
410
+ - #### **0.1.4** — Added experimental features in `Model Performance`
411
  "),
412
 
413
  br(),
 
426
 
427
  footer = shinydashboardPlus::dashboardFooter(
428
  left = "Powered by ❤️, ☕, Shiny, and 🤗 Spaces",
429
+ right = paste0("Version 0.1.4"))
430
 
431
  )
432
 
 
707
  "\nPayout:", round(payout,2), "NMR"))) +
708
  geom_bar(stat = "identity") +
709
  theme(
710
+ panel.border = element_rect(fill = 'transparent', color = "grey", linewidth = 0.25),
 
711
  panel.background = element_rect(fill = 'transparent'),
712
  plot.background = element_rect(fill = 'transparent', color = NA),
713
  panel.grid.major = element_blank(),
 
779
  formatRound(columns = c("total_stake", "net_payout", "rate_of_return"), digits = 2) |>
780
 
781
  formatStyle(columns = c("round"), fontWeight = "bold") |>
782
+
783
  formatStyle(columns = c("resolved"),
784
  target = "row",
785
  backgroundColor = styleEqual(c(1,0), c("transparent", "#FFF8E1"))) |>
 
802
  })
803
 
804
 
805
+ # ============================================================================
806
+ # Reactive: Model Performance Charts
807
+ # ============================================================================
808
+
809
+ # Boxplot - TC Percentile
810
+ output$plot_boxplot_tcp <- renderPlotly({
811
+
812
+ # Data
813
+ d_filter <- react_d_filter()
814
+
815
+ # Order by TC_PCT
816
+ d_ordered <- with(d_filter, reorder(model, tc_pct, median))
817
+ d_filter$group <- factor(d_filter$model, levels = levels(d_ordered))
818
+
819
+ # ggplot2
820
+ p <- ggplot(d_filter, aes(x = group, y = tc_pct, group = group, color = group)) +
821
+ geom_boxplot(fill = NA) +
822
+ theme(
823
+ panel.border = element_blank(),
824
+ panel.background = element_rect(fill = 'transparent'),
825
+ plot.background = element_rect(fill = 'transparent', color = NA),
826
+ panel.grid.major.x = element_blank(),
827
+ panel.grid.major.y = element_line(color = "grey", linewidth = 0.25),
828
+ panel.grid.minor = element_blank(),
829
+ strip.background = element_rect(fill = 'transparent'),
830
+ strip.text = element_text(),
831
+ strip.clip = "on",
832
+ legend.position = "none"
833
+ ) +
834
+ scale_color_manual(values = gen_custom_palette(d_filter$model)) +
835
+ xlab("Model") +
836
+ ylab("TC Percentile") +
837
+ scale_y_continuous(limits = c(0,100), breaks = breaks_pretty(4)) +
838
+ coord_flip()
839
+
840
+
841
+ # Dynamic height adjustment
842
+ n_model <- length(unique(d_filter$model))
843
+ height <- 600 # default
844
+ if (n_model > 10) height = 800
845
+ if (n_model > 15) height = 1000
846
+ if (n_model > 20) height = 1200
847
+ if (n_model > 25) height = 1400
848
+ if (n_model > 30) height = 1600
849
+ if (n_model > 35) height = 1800
850
+ if (n_model > 40) height = 2000
851
+ if (n_model > 45) height = 2200
852
+ if (n_model > 50) height = 2400
853
+
854
+ # Generate plotly
855
+ ggplotly(p, height = height)
856
+
857
+ })
858
+
859
+
860
  # ============================================================================
861
  # Reactive: Downloads
862
  # ============================================================================