Skip to content

Commit 234c4bd

Browse files
authored
Merge pull request #5 from Andryas/main
add example using shiny.fluent and dynamic routes /projectId/pages*
2 parents 0c6ca08 + 7d24a61 commit 234c4bd

28 files changed

Lines changed: 2479 additions & 0 deletions

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,4 @@ js/README.md
1212
docs
1313
inst/doc
1414
data-raw
15+
renv
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
if (file.exists("renv")) {
2+
source("renv/activate.R")
3+
} else {
4+
# The `renv` directory is automatically skipped when deploying with rsconnect.
5+
message("No 'renv' directory found; renv won't be activated.")
6+
}
7+
8+
# Allow absolute module imports (relative to the app root).
9+
options(box.path = getwd())
10+
11+
# box.lsp languageserver external hook
12+
if (nzchar(system.file(package = "box.lsp"))) {
13+
options(
14+
languageserver.parser_hooks = list(
15+
"box::use" = box.lsp::box_use_parser
16+
)
17+
)
18+
}

inst/examples/shiny.fluent/.lintr

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
linters:
2+
linters_with_defaults(
3+
defaults = box.linters::rhino_default_linters,
4+
line_length_linter = line_length_linter(100)
5+
)
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# Only use `dependencies.R` to infer project dependencies.
2+
*
3+
!dependencies.R

inst/examples/shiny.fluent/app.R

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# Rhino / shinyApp entrypoint. Do not edit.
2+
rhino::app()

inst/examples/shiny.fluent/app/js/index.js

Whitespace-only changes.
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# Logic: application code independent from Shiny.
2+
# https://go.appsilon.com/rhino-project-structure
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# openDota API example for fetching hero stats
2+
3+
print("Fetching hero stats from OpenDota API...")
4+
hero_stats <- httr::GET("https://api.opendota.com/api/heroStats")
5+
hero_stats <- httr::content(hero_stats)
6+
hero_stats
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#' @export
2+
primary_attr_color <- function(attr) {
3+
switch(
4+
attr,
5+
"str" = "darkred",
6+
"agi" = "darkgreen",
7+
"int" = "darkblue",
8+
"all" = "purple", # or "indigo"/"#6a0dad" if you want darker purple
9+
"black" # fallback/default
10+
)
11+
}
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
box::use(
2+
app / view / home,
3+
app / view / menu,
4+
app / view / details,
5+
app / view / benchmark,
6+
app / view / rank
7+
)
8+
9+
#' @export
10+
ui <- function(id) {
11+
ns <- shiny::NS(id)
12+
shiny::tagList(
13+
shiny.fluent::fluentPage(
14+
reactRouter::HashRouter(
15+
reactRouter::Routes(
16+
reactRouter::Route(
17+
path = "/",
18+
element = home$ui(ns("home"))
19+
),
20+
reactRouter::Route(
21+
path = "/:projectId/*",
22+
element = menu$ui(ns("menu")),
23+
children = list(
24+
reactRouter::Route(
25+
path = "details",
26+
element = details$ui(ns("details"))
27+
),
28+
reactRouter::Route(
29+
path = "benchmark",
30+
element = benchmark$ui(ns("benchmark"))
31+
),
32+
reactRouter::Route(
33+
path = "rank",
34+
element = rank$ui(ns("rank"))
35+
)
36+
)
37+
),
38+
reactRouter::Route(path = "*", element = "Custom error 404")
39+
)
40+
)
41+
)
42+
)
43+
}
44+
45+
#' @export
46+
server <- function(id) {
47+
shiny::moduleServer(id, function(input, output, session) {
48+
hero_selected <- home$server("home")
49+
50+
shiny::observe({
51+
shiny::req(hero_selected())
52+
53+
print(paste0("hero_id selected: ", hero_selected()))
54+
})
55+
56+
menu$server("menu", hero_selected = hero_selected)
57+
details$server("details", hero_selected = hero_selected)
58+
benchmark$server("benchmark", hero_selected = hero_selected)
59+
rank$server("rank", hero_selected = hero_selected)
60+
})
61+
}

0 commit comments

Comments
 (0)