Spaces:
Running
Running
0.1.2 - payout summary layout updates
Browse files
app/app.R
CHANGED
@@ -265,19 +265,21 @@ ui <- shinydashboardPlus::dashboardPage(
|
|
265 |
|
266 |
br(),
|
267 |
|
268 |
-
shinycssloaders::withSpinner(plotlyOutput("plot_payout_stacked"))
|
|
|
|
|
|
|
|
|
|
|
|
|
269 |
|
270 |
),
|
271 |
|
272 |
tabPanel("Individual Models",
|
273 |
br(),
|
274 |
-
shinycssloaders::withSpinner(plotlyOutput("plot_payout_individual")))
|
275 |
-
|
276 |
-
tabPanel("Summary Table",
|
277 |
-
br(), br(),
|
278 |
-
shinycssloaders::withSpinner(DTOutput("dt_payout_summary"))
|
279 |
-
)
|
280 |
|
|
|
281 |
)
|
282 |
|
283 |
)
|
@@ -315,6 +317,7 @@ ui <- shinydashboardPlus::dashboardPage(
|
|
315 |
"
|
316 |
- #### **0.1.0** — First prototype with an interactive table output
|
317 |
- #### **0.1.1** — Added a functional `Payout Summary`
|
|
|
318 |
"),
|
319 |
br(),
|
320 |
markdown("## **Session Info**"),
|
@@ -329,7 +332,7 @@ ui <- shinydashboardPlus::dashboardPage(
|
|
329 |
|
330 |
footer = shinydashboardPlus::dashboardFooter(
|
331 |
left = "Powered by ❤️, ☕, Shiny, and 🤗 Spaces",
|
332 |
-
right = paste0("Version 0.1.
|
333 |
|
334 |
)
|
335 |
|
@@ -466,6 +469,29 @@ server <- function(input, output) {
|
|
466 |
})
|
467 |
|
468 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
469 |
# ============================================================================
|
470 |
# Reactive: Payout Value Boxes
|
471 |
# ============================================================================
|
@@ -510,11 +536,13 @@ server <- function(input, output) {
|
|
510 |
# Stacked Bar Chart
|
511 |
output$plot_payout_stacked <- renderPlotly({
|
512 |
|
513 |
-
|
514 |
-
|
515 |
-
|
516 |
-
|
517 |
-
|
|
|
|
|
518 |
geom_bar(position = "stack", stat = "identity") +
|
519 |
theme(
|
520 |
panel.border = element_rect(fill = 'transparent',
|
@@ -533,7 +561,7 @@ server <- function(input, output) {
|
|
533 |
scale_fill_scico(palette = "vikO", direction = -1, midpoint = 0) +
|
534 |
xlab("Tournament Round") +
|
535 |
ylab("Payout (NMR)")
|
536 |
-
|
537 |
# Generate plotly
|
538 |
ggplotly(p, tooltip = "text")
|
539 |
|
@@ -565,7 +593,7 @@ server <- function(input, output) {
|
|
565 |
legend.background = element_rect(fill = 'transparent'),
|
566 |
legend.box.background = element_rect(fill = 'transparent')
|
567 |
) +
|
568 |
-
geom_hline(aes(yintercept = 0),
|
569 |
scale_fill_scico(palette = "vikO", direction = -1, midpoint = 0) +
|
570 |
xlab("Tournament Round") +
|
571 |
ylab("Confirmed / Pending Payout (NMR)")
|
@@ -601,20 +629,11 @@ server <- function(input, output) {
|
|
601 |
|
602 |
output$dt_payout_summary <- DT::renderDT({
|
603 |
|
604 |
-
# Summarise payout
|
605 |
-
d_smry <-
|
606 |
-
react_d_filter() |> lazy_dt() |>
|
607 |
-
group_by(round, resolved) |>
|
608 |
-
summarise(stake = sum(stake, na.rm = T),
|
609 |
-
payout = sum(payout, na.rm = T)) |>
|
610 |
-
as.data.table()
|
611 |
-
d_smry$rate_of_return <- (d_smry$payout / d_smry$stake) * 100
|
612 |
-
|
613 |
# Generate a new DT
|
614 |
DT::datatable(
|
615 |
|
616 |
# Data
|
617 |
-
|
618 |
|
619 |
# Other Options
|
620 |
rownames = FALSE,
|
@@ -624,21 +643,21 @@ server <- function(input, output) {
|
|
624 |
dom = 'Bflrtip', # https://datatables.net/reference/option/dom
|
625 |
buttons = list('csv', 'excel', 'copy', 'print'), # https://rstudio.github.io/DT/003-tabletools-buttons.html
|
626 |
order = list(list(0, 'asc'), list(1, 'asc')),
|
627 |
-
pageLength =
|
628 |
lengthMenu = c(5, 10, 20, 100, 500, 1000),
|
629 |
columnDefs = list(list(className = 'dt-center', targets = "_all")))
|
630 |
) |>
|
631 |
|
632 |
# Reformat individual columns
|
633 |
-
formatRound(columns = c("
|
634 |
|
635 |
formatStyle(columns = c("round"), fontWeight = "bold") |>
|
636 |
|
637 |
-
formatStyle(columns = c("
|
638 |
fontWeight = "bold",
|
639 |
color = styleInterval(cuts = -1e-15, values = c("#D24141", "#2196F3"))) |>
|
640 |
|
641 |
-
formatStyle(columns = c("
|
642 |
fontWeight = "bold",
|
643 |
color = styleInterval(cuts = c(-1e-15, 1e-15),
|
644 |
values = c("#D24141", "#D1D1D1", "#00A800"))) |>
|
|
|
265 |
|
266 |
br(),
|
267 |
|
268 |
+
shinycssloaders::withSpinner(plotlyOutput("plot_payout_stacked")),
|
269 |
+
|
270 |
+
br(),
|
271 |
+
br(),
|
272 |
+
br(),
|
273 |
+
|
274 |
+
DTOutput("dt_payout_summary")
|
275 |
|
276 |
),
|
277 |
|
278 |
tabPanel("Individual Models",
|
279 |
br(),
|
280 |
+
shinycssloaders::withSpinner(plotlyOutput("plot_payout_individual")))
|
|
|
|
|
|
|
|
|
|
|
281 |
|
282 |
+
|
283 |
)
|
284 |
|
285 |
)
|
|
|
317 |
"
|
318 |
- #### **0.1.0** — First prototype with an interactive table output
|
319 |
- #### **0.1.1** — Added a functional `Payout Summary`
|
320 |
+
- #### **0.1.2** — `Payout Summary` layout updates
|
321 |
"),
|
322 |
br(),
|
323 |
markdown("## **Session Info**"),
|
|
|
332 |
|
333 |
footer = shinydashboardPlus::dashboardFooter(
|
334 |
left = "Powered by ❤️, ☕, Shiny, and 🤗 Spaces",
|
335 |
+
right = paste0("Version 0.1.2"))
|
336 |
|
337 |
)
|
338 |
|
|
|
469 |
})
|
470 |
|
471 |
|
472 |
+
react_d_payout_summary <- eventReactive(
|
473 |
+
input$button_filter,
|
474 |
+
{
|
475 |
+
|
476 |
+
# Summarise payout
|
477 |
+
d_smry <-
|
478 |
+
react_d_filter() |> lazy_dt() |>
|
479 |
+
group_by(round, resolved) |>
|
480 |
+
summarise(stake = sum(stake, na.rm = T),
|
481 |
+
payout = sum(payout, na.rm = T)) |>
|
482 |
+
as.data.table()
|
483 |
+
d_smry$rate_of_return <- (d_smry$payout / d_smry$stake) * 100
|
484 |
+
|
485 |
+
# Rename
|
486 |
+
colnames(d_smry) <- c("round", "resolved", "total_stake",
|
487 |
+
"total_payout", "rate_of_return")
|
488 |
+
|
489 |
+
# Return
|
490 |
+
d_smry
|
491 |
+
|
492 |
+
})
|
493 |
+
|
494 |
+
|
495 |
# ============================================================================
|
496 |
# Reactive: Payout Value Boxes
|
497 |
# ============================================================================
|
|
|
536 |
# Stacked Bar Chart
|
537 |
output$plot_payout_stacked <- renderPlotly({
|
538 |
|
539 |
+
# ggplot
|
540 |
+
p <- ggplot(react_d_filter(),
|
541 |
+
aes(x = round, y = payout, fill = payout,
|
542 |
+
text = paste("Model:", model,
|
543 |
+
"\nRound:", round,
|
544 |
+
"\nResolved:", resolved,
|
545 |
+
"\nPayout:", round(payout,2), "NMR"))) +
|
546 |
geom_bar(position = "stack", stat = "identity") +
|
547 |
theme(
|
548 |
panel.border = element_rect(fill = 'transparent',
|
|
|
561 |
scale_fill_scico(palette = "vikO", direction = -1, midpoint = 0) +
|
562 |
xlab("Tournament Round") +
|
563 |
ylab("Payout (NMR)")
|
564 |
+
|
565 |
# Generate plotly
|
566 |
ggplotly(p, tooltip = "text")
|
567 |
|
|
|
593 |
legend.background = element_rect(fill = 'transparent'),
|
594 |
legend.box.background = element_rect(fill = 'transparent')
|
595 |
) +
|
596 |
+
geom_hline(aes(yintercept = 0), linewidth = 0.25, color = "grey") +
|
597 |
scale_fill_scico(palette = "vikO", direction = -1, midpoint = 0) +
|
598 |
xlab("Tournament Round") +
|
599 |
ylab("Confirmed / Pending Payout (NMR)")
|
|
|
629 |
|
630 |
output$dt_payout_summary <- DT::renderDT({
|
631 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
632 |
# Generate a new DT
|
633 |
DT::datatable(
|
634 |
|
635 |
# Data
|
636 |
+
react_d_payout_summary(),
|
637 |
|
638 |
# Other Options
|
639 |
rownames = FALSE,
|
|
|
643 |
dom = 'Bflrtip', # https://datatables.net/reference/option/dom
|
644 |
buttons = list('csv', 'excel', 'copy', 'print'), # https://rstudio.github.io/DT/003-tabletools-buttons.html
|
645 |
order = list(list(0, 'asc'), list(1, 'asc')),
|
646 |
+
pageLength = 100,
|
647 |
lengthMenu = c(5, 10, 20, 100, 500, 1000),
|
648 |
columnDefs = list(list(className = 'dt-center', targets = "_all")))
|
649 |
) |>
|
650 |
|
651 |
# Reformat individual columns
|
652 |
+
formatRound(columns = c("total_stake", "total_payout", "rate_of_return"), digits = 2) |>
|
653 |
|
654 |
formatStyle(columns = c("round"), fontWeight = "bold") |>
|
655 |
|
656 |
+
formatStyle(columns = c("total_stake"),
|
657 |
fontWeight = "bold",
|
658 |
color = styleInterval(cuts = -1e-15, values = c("#D24141", "#2196F3"))) |>
|
659 |
|
660 |
+
formatStyle(columns = c("total_payout"),
|
661 |
fontWeight = "bold",
|
662 |
color = styleInterval(cuts = c(-1e-15, 1e-15),
|
663 |
values = c("#D24141", "#D1D1D1", "#00A800"))) |>
|