Tychobra / polished

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

html anchors causing app reload #172

Closed kennedymwavu closed 2 years ago

kennedymwavu commented 2 years ago

HTML anchors to a different section on the same page were working fine but when I added authentication using {polished} the whole app now reloads causing any file uploaded to be lost and also any results calculated. I'm thinking it might be a possible bug on {polished}.

Here is a reprex:

ui.R:

# Function to add n linebreaks in page:
linebreaks <- function(n) {
  HTML(strrep(br(), n))
}

ui <- fluidPage(
  fileInput(
    inputId = "my_file",
    label = "Choose file"
  ),

  # anchor tag with btn inside:
  tags$a(
    href = "#button2", # scroll to element with id "button2" when clicked

    actionButton(
      inputId = "button1",
      label = "Button1"
    ),
  ),

  linebreaks(50),

  # another anchor tag with btn inside:
  tags$a(
    href = "#button1", # scroll to element with id "button1" when clicked

    actionButton(
      inputId = "button2",
      label = "Button2"
    ),

  ),

  linebreaks(50)
)

polished::secure_ui(ui)

server.R:

server <- function(input, output, session) {

}

polished::secure_server(server)

global.R:

library(shiny)
library(polished)

# configure {polished} global sessions when the app initially starts up.
polished::global_sessions_config(
  app_name = "my-app",
  api_key = "my-secret-api-key"
)
merlinoa commented 2 years ago

Hi @kennedymwavu

Thanks for the bug report and reprex. I just pushed an update that should fix this issue: 67ec32fcc940a0ae7bc516e79f7ecc5cc32370af

The issue was occurring because we were reloading the app whenever the hash or query parameters changed. We were doing this to allow for normal use of the browser's forward and back buttons when navigating between the admin panel and the Shiny app using polished, but it was causing this issue when changing the url params, but staying on the same Shiny app. This update should make it so the app reload only occurs for the appropriate navigation events and not whenever the url hash or query updates.

Let me know if you are still running into the issue.

kennedymwavu commented 2 years ago

Hi @merlinoa The issue has been fixed. Thanks a lot.