Tychobra / polished

Authentication and Administration for Shiny apps
https://polished.tech
Other
233 stars 36 forks source link

Logos on login-in screen don't show up when visiting the page for the first time #213

Closed fegue closed 1 year ago

fegue commented 1 year ago

I use polished in a Shiny app developed with the golem package. The function sign_in_ui_default() is configured in run_app.R. The images are stored in inst/app/www and the path is added to the app via add_resource_path().

The app is deployed on shinyapps.io. When visiting the page the first time, the alt text is displayed instead of the logos. This happens independent of the browser. After logging out again, the logos are being displayed. After that the logos get displayed but only for some time. After a while (maybe after reboot?) the logos disappear again.

Is this a bug or am I doing something wrong?

Here is the code in run_app.R

run_app <- function(
    onStart = NULL,
    options = list(),
    enableBookmarking = NULL,
    uiPattern = "/",
    ...
){
  polished::polished_config(
    app_name = "APP_NAME",
    api_key = "XXXX",
    cookie_expires = NULL
  )
  my_custom_sign_in_page <- polished::sign_in_ui_default(
    sign_in_module = polished::sign_in_module_ui("sign_in", register_link = NULL),
    color = "#999999",
    company_name = "My Company",
    logo_top = tags$img(
      src = "www/logo.png",
      alt = "Logo: LOGO",
      style = "width: 155px; margin-top: 30px; margin-bottom: 30px;"
    ),
    logo_bottom = tags$img(
      src = "www/otherLogo.png",
      alt = "Logo: otherLogo",
      style = "width: 200px; margin-bottom: 15px; padding-top: 15px;"
    ),
    icon_href = "www/logo.png"
  )

  with_golem_options(
    app = shinyApp(
      ui = polished::secure_ui(app_ui,sign_in_page_ui = my_custom_sign_in_page), 
      server = polished::secure_server(app_server), 
      onStart = onStart,
      options = options,
      enableBookmarking = enableBookmarking,
      uiPattern = uiPattern
    ),
    golem_opts = list(...)
  )
}

Thank you for the help!

merlinoa commented 1 year ago

I don't think you need the "www" prefix on your image paths. Everything in "www" is accessible from the root path.

cwilligv commented 1 year ago

Just contributing with my experience. In my custom_sign_in_ui_page I too have images displayed correctly and as @merlinoa said, I also omit www in the picture path as that's already accessible from the app.

fegue commented 1 year ago

I followed your suggestion and removed the 'www' prefix. Then the logos won't be displayed anymore. The way the images are referenced is the default and the recommended golem way.

  add_resource_path(
    "www",
    app_sys("app/www")
  )

But the problem is not that the images never show up. The problem is that the logos don't appear when visiting the page the first time. And this problem only occurs when the app is deployed.

I do not feel comfortable making guesses here, but could the problem have something to do with caching the images but not having access on the first Log-In?

fegue commented 1 year ago

Just contributing with my experience. In my custom_sign_in_ui_page I too have images displayed correctly and as @merlinoa said, I also omit www in the picture path as that's already accessible from the app.

Do you use the golem package?

merlinoa commented 1 year ago

I do not normally use golem, but I just updated this example golem app using polished to work with a custom sign in page a custom image: https://github.com/Tychobra/polished_example_apps/blob/master/08_golem_app/R/run_app.R

merlinoa commented 1 year ago

Going to close this out since it should be possible by following the example app linked above. Feel free to reopen if you are still having issues.

fegue commented 1 year ago

This is fixing it for me! The path www/app now gets added as a resource both in app_ui.R and run_app.R. This doesn't feel optimal but it works.

Thank you for your help!