Skip to content

Commit

Permalink
better layout + add modal for no selection + tweaks
Browse files Browse the repository at this point in the history
  • Loading branch information
DivadNojnarg committed Nov 15, 2023
1 parent 82190eb commit 6fa99fd
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 5 deletions.
28 changes: 27 additions & 1 deletion inst/showcase/app.R
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,40 @@ ui <- nextui_page(
)
)
)
)
),
reactOutput("no_pokemon_modal")
)

server <- function(input, output, session) {
main <- mod_poke_select_server("poke_select_1")
mod_poke_info_server("poke_info_1", main$selected, main$is_shiny)
mod_poke_stats_server("poke_stats_1", main$selected, reactive(input$theme))
mod_poke_move_server("poke_move_1", main$selected, reactive(input$theme))

modalVisible <- reactiveVal(FALSE)
observeEvent(main$select_state(), {
if (is.null(main$select_state())) modalVisible(TRUE)
}, ignoreNULL = FALSE, ignoreInit = TRUE)

observeEvent(input$modal_closed, {
modalVisible(FALSE)
})

output$no_pokemon_modal <- renderReact({
modal(
scrollBehavior = input$scroll,
isOpen = modalVisible(),
size = "sm",
backdrop = "blur",
onClose = JS(
"() => Shiny.setInputValue('modal_closed', true, {priority: 'event'})
"),
modal_content(
modal_header("Oups, no pokemon is selected ..."),
modal_body("Select a pokemon to see the data!")
)
)
})
}

shinyApp(ui, server)
10 changes: 9 additions & 1 deletion inst/showcase/modules/mod_poke_move.R
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,15 @@ mod_poke_move_server <- function(id, selected, theme) {
},
pp = move$pp,
priority = move$priority,
accuracy = move$accuracy,
accuracy = if (is.na(move$accuracy)) {
"NA"
} else {
progress(
value = move$accuracy,
maxValue = 100,
showValueLabel = TRUE
)
},
text = move$text
)
})
Expand Down
3 changes: 2 additions & 1 deletion inst/showcase/modules/mod_poke_select.R
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,8 @@ mod_poke_select_server <- function(id) {
return(
list(
selected = selected_pokemon,
is_shiny = reactive(input$is_shiny)
is_shiny = reactive(input$is_shiny),
select_state = reactive(input$selected)
)
)
})
Expand Down
5 changes: 3 additions & 2 deletions inst/showcase/modules/mod_poke_stats.R
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
other_stats_names <- function() {
names(poke_data[[1]]$other_stats)
#names(poke_data[[1]]$other_stats)
c("height", "weight", "capture_rate")
}

extra_from_list <- function(l, key = "name", type = character(1)) {
Expand Down Expand Up @@ -171,7 +172,7 @@ mod_poke_stats_server <- function(id, selected, theme) {
# card wrapper for the charts
output$poke_stats_card <- renderUI({
req(!is.null(selected()))
echarts4rOutput(outputId = ns("poke_stats"), height = "700px")
echarts4rOutput(outputId = ns("poke_stats"))
})
})
}

0 comments on commit 6fa99fd

Please sign in to comment.