Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor #1

Open
wants to merge 8 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import(bsicons)
import(echarts4r)
import(shiny)
import(tablerDash)
import(waiter)
importFrom(dplyr,across)
importFrom(dplyr,all_of)
importFrom(dplyr,as_tibble)
Expand Down
75 changes: 37 additions & 38 deletions R/app_server.R
Original file line number Diff line number Diff line change
Expand Up @@ -13,52 +13,51 @@ app_server <- function(input, output, session) {
class = "btn-success"
)

observeEvent(TRUE, {
showModal(
modalDialog(
title = "WeLCOME to the PoKeMON APP",
"Do you want to start the app!",
size = "s",
footer = tagList(
cancel_btn,
actionButton(
"continue",
"Continue",
class = "btn-danger",
`data-dismiss` = "modal"
)
)
)
)
})
# observeEvent(TRUE, {
# showModal(
# modalDialog(
# title = "WeLCOME to the PoKeMON APP",
# "Do you want to start the app!",
# size = "s",
# footer = tagList(
# cancel_btn,
# actionButton(
# "continue",
# "Continue",
# class = "btn-danger",
# `data-dismiss` = "modal"
# )
# )
# )
# )
# })

observeEvent(input$continue, {
showModal(
modalDialog(
title = "The N1 poKemON APP IN THE WORLD!!!!",
size = "s",
"Please confirm",
footer = tagList(
modalButton("continue"),
actionButton(
"cancel",
"Cancel",
class = "btn-success",
`data-dismiss` = "modal"
)
)
)
)
}, priority = 10)
# observeEvent(input$continue, {
# showModal(
# modalDialog(
# title = "The N1 poKemON APP IN THE WORLD!!!!",
# size = "s",
# "Please confirm",
# footer = tagList(
# modalButton("continue"),
# actionButton(
# "cancel",
# "Cancel",
# class = "btn-success",
# `data-dismiss` = "modal"
# )
# )
# )
# )
# }, priority = 10)

observeEvent(input$cancel, {
session$reload()
})

main <- mod_poke_select_server("poke_select_1")
mod_poke_info_server("poke_info_1", main$selected, main$is_shiny)
mod_poke_info_server("poke_info_1", main$selected)
mod_poke_type_server("poke_type_1", main$selected)
mod_poke_evolve_server("poke_evolve_1", main$selected, main$is_shiny)
mod_poke_stats_server("poke_stats_1", main$selected)
mod_poke_move_server("poke_move_1", main$selected)
mod_poke_location_server("poke_location_1", main$selected)
Expand Down
110 changes: 44 additions & 66 deletions R/app_ui.R
Original file line number Diff line number Diff line change
Expand Up @@ -3,70 +3,56 @@
#' @param request Internal parameter for `{shiny}`.
#' DO NOT REMOVE.
#' @noRd
#' @import waiter
app_ui <- function(request) {

nav_tag <- tablerDashNav(
id = "mymenu",
src = "https://www.ssbwiki.com/images/9/9c/Master_Ball_Origin.png",
navMenu = tablerNavMenu(
tablerNavMenuItem(
tabName = "PokeInfo",
icon = "home",
h1("PokeInfo", style = "color: green"),
style = "background-color: grey",
)
),
# Select input UI module
mod_poke_select_ui("poke_select_1"),
tablerDropdown(
tablerDropdownItem(
title = NULL,
href = "https://pokeapi.co",
url = "https://pokeapi.co/static/logo-6221638601ef7fa7c835eae08ef67a16.png",
status = "success",
date = NULL,
"This app use pokeApi by Paul Hallet and PokeAPI contributors."
)
)
)

nav_tag[[1]]$attribs$style <- paste0(
nav_tag[[1]]$attribs$style,
"background-color: yellow"
)
#nav_tag <- tablerDashNav(
# id = "mymenu",
# src = "https://www.ssbwiki.com/images/9/9c/Master_Ball_Origin.png",
# mod_poke_select_ui("poke_select_1")
#)

tagList(
# Leave this function for adding external resources
golem_add_external_resources(),
# Your application UI logic
tablerDashPage(
navbar = nav_tag,
footer = tablerDashFooter(
copyrights = "Disclaimer: this app is purely intended for learning purpose. @David Granjon, 2023"
),
title = "Gotta Catch'Em (Almost) All",
body = tablerDashBody(
style = "background-color: brown",
tablerTabItems(
tablerTabItem(
tabName = "PokeInfo",
fluidRow(
column(
width = 8,
mod_poke_info_ui("poke_info_1"),
mod_poke_type_ui("poke_type_1"),
mod_poke_evolve_ui("poke_evolve_1")
),
column(
width = 4,
mod_poke_stats_ui("poke_stats_1"),
mod_poke_move_ui("poke_move_1"),
mod_poke_location_ui("poke_location_1")
)
)
)
)
waiter::waiterPreloader(
html = tagList(
tags$div(class="pokeball",
tags$div(class="pokeball__button")
),
"Loading ..."
)
),
bslib::page_fluid(
title = "PokeApp",
br(),
jumbotron("Gotta Catch'Em (Almost) All"),
tags$div(class = "d-flex justify-content-center my-5", mod_poke_select_ui("poke_select_1")),

bslib::layout_columns(
col_widths = c(4, 8),
bslib::layout_columns(
width = 1,
mod_poke_info_ui("poke_info_1"),
mod_poke_location_ui("poke_location_1")
),
mod_poke_stats_ui("poke_stats_1")
),

#tags$section(
# class = "section-body",
# tags$div(
# class = "left",
# mod_poke_info_ui("poke_info_1"),
# mod_poke_location_ui("poke_location_1")
# ),
# tags$div(class="right", mod_poke_stats_ui("poke_stats_1"))
#),
# style = "background-color: brown",
mod_poke_move_ui("poke_move_1"),
mod_poke_type_ui("poke_type_1"),
footer = "Disclaimer: this app is purely intended for learning purpose. @David Granjon, 2023"
)
)
}
Expand All @@ -90,15 +76,7 @@ golem_add_external_resources <- function() {
path = app_sys("app/www"),
app_title = "shinyMons2"
),
# custom font setup
tags$link(
href = "https://fonts.googleapis.com/css?family=Press+Start+2P",
rel = "stylesheet"
),
tags$style(
"html, body, pre, code, kbd, samp {
font-family: 'Press Start 2P';
}"
)
# Screen loader
waiter::useWaiter()
)
}
101 changes: 46 additions & 55 deletions R/mod_poke_evolve.R
Original file line number Diff line number Diff line change
@@ -1,62 +1,53 @@
#' poke_evolve UI Function
#'
#' @description A Module.
#'
#' @param id,input,output,session Internal parameters for {}.
#'
#' @noRd
mod_poke_evolve_ui <- function(id) {
ns <- NS(id)
uiOutput(ns("poke_evolve"))
}

#' poke_evolve Server Functions
#'
#' @param selected Selected pokemon data.
#' @param is_shiny Is the pokemon under its shiny form?
#'
#' @noRd
mod_poke_evolve_server <- function(id, selected, is_shiny) {
moduleServer(id, function(input, output, session) {

# treat data and generate the timeline
output$poke_evolve <- renderUI({
req(!is.null(selected()))
evol <- selected()$evolve_from
#' poke_evolve UI Function
#'
#' @description A Module.
#'
#' @param id,input,output,session Internal parameters for {}.
#'
#' @noRd
mod_poke_evolve_ui <- function(id) {
ns <- NS(id)
uiOutput(ns("poke_evolve"))
}

# If pokemon can't evolve ...
if (length(evol) == 0) {
tablerAlert(
title = "Alert",
"This Pokemon is a base pokemon.",
icon = "thumbs-up",
status = "success"
)
} else {
# Check that the evolution belongs to the first 151 pkmns ...
if (evol$id <= 151) {
tablerTimelineItem(
title = paste0("Evolves from: ", evol$name),
status = "green",
date = NULL,
img(
src = if (is_shiny()) {
poke_data[[evol$id]]$sprites$front_shiny
} else {
poke_data[[evol$id]]$sprites$front_default
}
)
#' poke_evolve Server Functions
#'
#' @param selected Selected pokemon data.
#' @param is_shiny Is the pokemon under its shiny form?
#'
#' @noRd
mod_poke_evolve_server <- function(id, selected) {
moduleServer(id, function(input, output, session) {

# treat data and generate the timeline
output$poke_evolve <- renderUI({
req(!is.null(selected()))
evol <- selected()$evolve_from

img <- NULL
# If pokemon can't evolve ...
if (length(evol) == 0) {
tags$div(
tags$p("Base Pokemon", class="evolution-text-inside"),
)
} else {
tablerAlert(
title = "Alert",
"This pokemon is an evolution of another pokemon but not
in the first generation.",
icon = "thumbs-up",
status = "success"
)
# Check that the evolution belongs to the first 151 pkmns ...
if (evol$id <= 151) {
tags$div(
tags$p("Evolves From", class="evolution-text"),
tags$img(
src = poke_data[[evol$id]]$sprites$front_shiny,
)
)
} else {
tags$div(
tags$p("Not first generation", class="evolution-text-inside"),
)
}
}
}

})
})
})
}
}
Loading