在用户使用Shinyauth看到应用程序的任何部分之前,如何要求在RShiny中进行用户身份验证?

我有一个 R Shiny 应用程序,我希望用户在看到任何东西之前进行身份验证,包括主面板和每个选项卡。我知道我可以req(credentials()$user_auth)在每个项目之前使用“ ”,但这对我的主面板来说似乎有点过分。但是,如果我不这样做,它看起来很尴尬:

我怎样才能在用户看到任何东西之前要求凭据?有没有办法只指定一次 above-req() 参数?

我知道shinymanager可以通过 secureapp() 函数做到这一点,但据我所知,您不能使用散列密码。我的应用程序使用sodium 包来散列密码,因此最好使用shinyauhr,因为它可以轻松解码。仅当他们可以使用散列密码时才对其他解决方案开放。

这是一个可重现的示例:

library(shiny)
library(shinyauthr)

user_base <- tibble::tibble(
  user = c("user1", "user2"),
  permissions = c("admin", "standard"),
  name = c("User One", "User Two"),
  pwd_col = "password"
)


ui <- fluidPage(
  # add logout button UI
  div(class = "pull-right", shinyauthr::logoutUI(id = "logout")),
  # add login panel UI function
  shinyauthr::loginUI(id = "login"),
  tabsetPanel(
    tabPanel("View 1", 
  
  h4("Select Your Desired Filters"),
  div(id = "inputs",
      dateRangeInput(
        inputId = "date_filter",
        label = "Filter by Month and Year",
        start = today(),
        end = (today() + 90),
        min = "Apr-2021",
        max = NULL,
        format = "M-yyyy",
        startview = "month",
        weekstart = 0,
        language = "en",
        separator = " to ",
        width = NULL,
        autoclose = TRUE
      ))),
  tabPanel("View 2", 
  # setup table output to show user info after login
  tableOutput("user_table")
)))

server <- function(input, output, session) {
  
  # call login module supplying data frame, 
  # user and password cols and reactive trigger
  credentials <- shinyauthr::loginServer(
    id = "login",
    data = user_base,
    user_col = user,
    pwd_col = pwd_col,
    sodium_hashed = FALSE,
    log_out = reactive(logout_init())
  )
  
  # call the logout module with reactive trigger to hide/show
  logout_init <- shinyauthr::logoutServer(
    id = "logout",
    active = reactive(credentials()$user_auth)
  )
  
  output$user_table <- renderTable({
    # use req to only render results when credentials()$user_auth is TRUE
    req(credentials()$user_auth)
    credentials()$info
  })
}

shinyApp(ui = ui, server = server)

以上是在用户使用Shinyauth看到应用程序的任何部分之前,如何要求在RShiny中进行用户身份验证?的全部内容。
THE END
分享
二维码
< <上一篇
下一篇>>