rauthenticationshinyshinyappsgolem

How do I use {polished} package with {brochure} framework?


This was a complicating in logic execution i came across using {polished} and {brochure}. When placing secure_ui/secure_server inside of a brochure::Page() in the same order of the example given by the {polished} dev team, there are changes to how a Shiny App is deploy on the {brochure} infrastructure. I was not sure where to relocate the polsiehd logic to.

Differences


Solution

  • When needing to merge the two logics you must:

    1. move polished_config() in globals.R --> golem::runApp() [initiate global setting for brochureApp()]
    run_app <- function(
      onStart = NULL,
      options = list(),
      enableBookmarking = NULL,
      ...
    ) {
    
      # old 'globals.R' logic 
      polished_config(
        app_name = "humblFinance",
        api_key = "xxxx"
      )
    
      with_golem_options(
        app = brochureApp(
          # Putting the resources here
          golem_add_external_resources(),
          page1(),
        ),
        golem_opts = list(...)
      )
    }
    
    1. wrap each brochure::page() ui/server with polished::secure_ui/server()`
    # an example login page
    login <- function(id = "login", href = "/login") {
    
    
      page(
        href = href,
        ui = secure_ui(
          mod_login_ui(id = id),
          sign_in_page_ui = sign_in_custom()
          ),
        server = secure_server(
          function(input, output, session) {
          mod_login_server(id = id)
          }
        )
      )
    }
    

    NOTE

    sign_in_custom() is a function that returns a customized UI object from polished::sign_in_default() to create personal business webpages. I would recommend wrapping polished::sign_in_default() in a custom global function since you will need to define this on ever brochure::page() that you want to have protected behind polished auth.

    once you authenticate one page through polished, you will be able to access all other protected pages while you are still logged in. After loggign out and attempting to access any one of the protected pages will result in a custom login page