R 有密码保护的仪表板选项卡位于闪亮的
我正在尝试改编Paul Campbell的shinyauthr示例 创建带有密码验证的闪亮仪表板。我尝试了很多选择,我也读过关于类似问题的问题,但我无法调整它们来解决我的问题。我需要密码才能访问仪表板,但无法将内容放入仪表板选项卡 这是我的最小工作示例,它试图扩展Paul的示例R 有密码保护的仪表板选项卡位于闪亮的,r,shiny,dashboard,shinyjs,R,Shiny,Dashboard,Shinyjs,我正在尝试改编Paul Campbell的shinyauthr示例 创建带有密码验证的闪亮仪表板。我尝试了很多选择,我也读过关于类似问题的问题,但我无法调整它们来解决我的问题。我需要密码才能访问仪表板,但无法将内容放入仪表板选项卡 这是我的最小工作示例,它试图扩展Paul的示例 library(shiny) library(shinyauthr) library(shinyjs) library(shinydashboard) # dataframe that holds usernames,
library(shiny)
library(shinyauthr)
library(shinyjs)
library(shinydashboard)
# dataframe that holds usernames, passwords and other user data
user_base <- data.frame(
user = c("user1", "user2"),
password = c("pass1", "pass2"),
permissions = c("admin", "standard"),
name = c("User One", "User Two"),
stringsAsFactors = FALSE
)
ui <-dashboardPage(
dashboardHeader(title = "Hello"),
dashboardSidebar(
sidebarMenu("Select Security", tabName = "select_security"),
sidebarMenu("Portfolio", tabName = "portfolio")
),
dashboardBody(
shinyjs::useShinyjs(),
div(class = "pull-right", shinyauthr::logoutUI(id = "logout")),
shinyauthr::loginUI(id = "login"),
tags$div(tabName = "portfolio", tableOutput("user_table"),
class = "tab_content"),
tags$div(tabName = "select_security", textOutput("welcome_note"), class = "tab_content")
)
)
server <- function(input, output, session) {
logout_init <- callModule(shinyauthr::logout,
id = "logout",
active = reactive(credentials()$user_auth))
credentials <- callModule(shinyauthr::login,
id = "login",
data = user_base,
user_col = user,
pwd_col = password,
log_out = reactive(logout_init()))
output$user_table <- renderTable({
req(credentials()$user_auth)
user_data()
})
output$welcome_note <- renderText({
req(credentials()$user_auth)
print("Hello")
})
}
shinyApp(ui = ui, server = server)
库(闪亮)
图书馆(shinyauthr)
图书馆(shinyjs)
图书馆(shinydashboard)
#保存用户名、密码和其他用户数据的数据框
user_base我认为我解决了这个问题,我认为这就是答案。每个选项卡都有自己的输入,只有在提供密码时才会显示
library(shiny)
library(shinyauthr)
library(shinyjs)
library(shinydashboard)
ui <- dashboardPage(
dashboardHeader(title = "My Dashboard",
dashboardSidebar(
shinyjs::useShinyjs(),
sidebarMenu(
menuItem("Security Selection", tabName = "security_selection", icon = icon("dashboard")),
menuItem("Portfolio", tabName = "portfolio", icon = icon("th"))
),
dashboardBody(
useShinyjs(),
tags$head(tags$style(".table{margin: 0 auto;}"),
tags$script(src="https://cdnjs.cloudflare.com/ajax/libs/iframe-resizer/3.5.16/iframeResizer.contentWindow.min.js",
type="text/javascript"),
includeScript("returnClick.js")
),
shinyauthr::loginUI("login"),
tabItems(
# first tab content
tabItem(tabName = "security_selection", uiOutput("security_selection")),
tabItem(tabName = "portfolio", uiOutput("portfolio"))
)
)
)
server <- function(input, output, session) {
credentials <- callModule(shinyauthr::login, "login",
data = user_base,
user_col = user,
pwd_col = password_hash,
sodium_hashed = TRUE,
log_out = reactive(logout_init()))
logout_init <- callModule(shinyauthr::logout, "logout", reactive(credentials()$user_auth))
user_info <- reactive({credentials()$info})
user_data <- reactive({
req(credentials()$user_auth)
output$security_selection <- renderUI({
req(credentials()$user_auth)
tagList(selectInput("name", "Name", choice = "user1", selected = "user1"),
selectInput("asset", "Asset", choice = c("Equity", "Debt", "Gold", "BTC"),
selected = "SPY"),
selectInput("action", "Action", choice = c("Buy", "Sell"), selected = "Buy"),
numericInput("quantity", "Assets to buy or sell", value = 100, min = 0,
max = 10e6),
actionButton("submit", "Submit")
)
})
output$portfolio <- renderUI({
req(credentials()$user_auth)
tabItem("portfolow",
tags$p("THis is a note")
)
})
}
shiny::shinyApp(ui, server)
库(闪亮)
图书馆(shinyauthr)
图书馆(shinyjs)
图书馆(shinydashboard)
用户界面