Skip to content

Commit

Permalink
Fix demo app and update package dependencies (#202)
Browse files Browse the repository at this point in the history
* chore: update dependencies

* fix: demo app to use new interfaces

---------

Co-authored-by: Jakub Sobolewski <[email protected]>
  • Loading branch information
jakubsob and Jakub Sobolewski committed Aug 31, 2023
1 parent f2f19e1 commit ed1c67e
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 20 deletions.
3 changes: 2 additions & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@ Suggests:
RColorBrewer,
rmarkdown,
sass,
shiny.router,
shiny.i18n (>= 0.3.0),
shiny.router (>= 0.3.1),
shinyjs,
sortable,
stringi,
Expand Down
33 changes: 14 additions & 19 deletions inst/examples/demo/app.R
Original file line number Diff line number Diff line change
Expand Up @@ -12,36 +12,25 @@ library(dplyr)
i18n <- Translator$new(translation_csvs_path = "translation")
i18n$set_translation_language("en")

# Add shiny.router dependencies manually: they are not picked up because they're added in a non-standard way.
shiny::addResourcePath("shiny.router", system.file("www", package = "shiny.router"))
shiny_router_js_src <- file.path("shiny.router", "shiny.router.js")
shiny_router_script_tag <- shiny::tags$script(type = "text/javascript", src = shiny_router_js_src)

lang_options <- list(
list(key = "en", text = "English"),
list(key = "pl", text = "Polish")
)

details_list_columns <- function() {
details_list_columns <- function(i18n) {
tibble(
fieldName = c("rep_name", "date", "deal_amount", "client_name", "city", "is_closed"),
name = c(i18n$t("Sales rep"), i18n$t("Close date"), i18n$t("Amount"), i18n$t("Client"), i18n$t("City"), i18n$t("Is closed?")),
key = fieldName
)
}

router <- make_router(
route("/", homePage(i18n)),
route("other", analysisPage(i18n))
)

sass(sass_file("style.scss"), output = "www/style.css")

ui <- fluentPage(
tags$head(
tags$link(href = "style.css", rel = "stylesheet", type = "text/css"),
shiny_router_script_tag,
shiny.i18n::usei18n(i18n)
usei18n(i18n)
),
div(
class = "grid-container",
Expand All @@ -53,22 +42,28 @@ ui <- fluentPage(
Dropdown.shinyInput("language", options = lang_options, value = "en")
)
),
div(class = "main", router$ui),
div(
class = "main",
router_ui(
route("/", homePage(i18n)),
route("other", analysisPage(i18n))
)
),
div(class = "footer", footer(i18n))
)
)

server <- function(input, output, session) {
router$server(input, output, session)
router_server(root_page = "/")
tr <- reactiveVal()

observeEvent(input$language, {
lang <- input$language
update_lang(session, lang)
update_lang(lang)
i18n$set_translation_language(lang)
tr(i18n)
})

observe({
req(tr())
newOptions <- purrr::map(lang_options, ~ list(key = .x$key, text = tr()$t(.x$text)))
Expand Down Expand Up @@ -118,7 +113,7 @@ server <- function(input, output, session) {

output$filteredSalesReps <- renderUI({
items_list <- if(nrow(filteredDeals()) > 0){
DetailsList(items = filteredDeals(), columns = details_list_columns())
DetailsList(items = filteredDeals(), columns = details_list_columns(i18n))
} else {
p(i18n$t("No matching transactions."))
}
Expand Down

0 comments on commit ed1c67e

Please sign in to comment.