You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

关于Shinymanager与Golem框架对接的技术咨询

Absolutely! Integrating shinymanager with the golem framework is totally feasible—here's a step-by-step guide with code snippets tailored to your setup, where credentials are stored in a credentials.sqlite file in your package directory.

Step 1: Organize Your Credential File

First, place your credentials.sqlite file in the inst/ directory of your golem project. Golem automatically includes files from inst/ in the installed package, so this ensures your credential database will be accessible when the app runs (either in development or after installation).

Step 2: Secure the UI (in app_ui.R)

Wrap your golem app's UI inside shinymanager::secure_app() just like you would in a traditional Ui.R/Server.R setup. Here's how to modify the default app_ui function:

#' The application User-Interface
#'
#' @param request Internal parameter for `{shiny}`. DO NOT REMOVE.
#' @import shiny
#' @import shinymanager
#' @noRd
app_ui <- function(request) {
  tagList(
    golem_add_external_resources(), # Keep this for external assets
    # Wrap your app UI in secure_app()
    secure_app(
      fluidPage(
        h1("My Secured Golem Application"),
        # Add your golem modules here
        mod_dashboard_ui("dashboard_module_1")
      )
    )
  )
}

Step 3: Handle Authentication in the Server (in app_server.R)

Use shinymanager::secure_server() to validate credentials against your SQLite database. We'll use system.file() to safely reference the database file in your package's inst/ directory:

#' The application server-side
#'
#' @param input,output,session Internal parameters for `{shiny}`. DO NOT REMOVE.
#' @import shiny
#' @import shinymanager
#' @noRd
app_server <- function(input, output, session) {
  # Authenticate users against the SQLite database
  auth_result <- secure_server(
    check_credentials = check_credentials(
      db = system.file("credentials.sqlite", package = "your_package_name")
    )
  )

  # Optional: Access authenticated user info
  observe({
    user_info <- reactiveValuesToList(auth_result)
    cat("Logged in user:", user_info$user, "\n")
  })

  # Run your golem modules as usual
  callModule(mod_dashboard_server, "dashboard_module_1")
}

Key Notes

  • Replace your_package_name with the actual name of your golem package.
  • During development, you can run the app with golem::run_app()—the system.file() call will still find the database in inst/.
  • If you update credentials.sqlite, restart your R session or reload the package to pick up changes.

内容的提问来源于stack exchange,提问作者Sofiane M'barki

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.08 09:52:30