基于用户登录的反应式过滤-ShinyAuthr反应式、用户登录、ShinyAuthr

2023-09-03 14:09:09 作者:久孤

我有一个QA闪亮的Dashboard应用程序,它有一个主数据集,必须根据用户登录详细信息筛选后续表/映射中使用的行。

例如:如果用户使用特定用户名(Location@email.com)登录,则反应函数会选择包含该用户名的行,并将这些行传递给闪亮的应用程序进行呈现。

机器学习 九 协同过滤算法

基本前提示例:

username <- "location@email.com"

new_dataset <- filter(dataset, column %like% username

output$table <- renderTable ({
  new_dataset
)}

我正在使用Shiny Author包来创建它,但我在将内置Shinyauthr函数创建的用户登录详细信息传递给反应函数时遇到了困难。代码如下:

users <- data.frame(user= c("user1", "user2", "user3"),
                         password = c("pass1", "pass2", "pass3"),
                         stringsAsFactors = FALSE)

ui <- dashboardPage(

  dashboardHeader(
    title = "QA App",

    tags$li(class = "dropdown", style = "padding: 8px;", shinyauthr::logoutUI("logout"))
  ),

  dashboardSidebar(
    collapsed = TRUE, sidebarMenuOutput("sidebar")
  ),

  dashboardBody(

    shinyjs::useShinyjs(),

    # shinyauthr login ui module here
    shinyauthr::loginUI("login"),

    tabItems(
      tabItem("tab", uiOutput("tab1_ui"))
    )
  )
)

server <- function(input, output) {

credentials <- callModule(shinyauthr::login, "login", 
                          data = users,
                          user_col = user,
                          pwd_col = password,
                          sodium_hashed = FALSE,
                          log_out = reactive(logout_init()))


# logout status managed by shinyauthr module and stored here
logout_init <- callModule(shinyauthr::logout, "logout", reactive(credentials()$user_auth))

output$sidebar <- renderMenu({
  req(credentials()$user_auth)
  sidebarMenu(

    menuItem("Tab", tabName = "tab", icon = icon("arrows-alt-v"))

  )
})

output$tab1_ui <- renderUI({

  req(credentials()$user_auth)
  fluidPage(

    mainPanel(
             tableOutput("table"),
      )
     )
  })
}

shinyApp(ui = ui, server = server)

我希望创建一个反应函数,该函数将呈现这个new_DataSet,并将其传递给UI中的表输出。问题是如何将用户登录凭据作为字符串访问以用于筛选?

推荐答案

就像这些案例中经常发生的那样,许多争论最终导致了答案,但我会在这里发布我的解决方案,以防有人遇到类似的问题。

R2Evans是正确的,因为它可以使用凭据()$INFO进行调用。问题是尝试使用EventReactive,而不是简单的被动。

被动用户详细信息通过以下方式收集:

credentials <- callModule(shinyauthr::login, "login", 
                          data = user_base,
                          user_col = user,
                          pwd_col = password,
                          sodium_hashed = FALSE,
                          log_out = reactive(logout_init()))

user_info <- reactive({credentials()$info})

filteredData <- reactive({
  filter(table, column %like% as.character(user_info()$user))
})

output$table <- renderTable(filteredData())
 
精彩推荐
图片推荐