我在下面有一個閃亮的應用程式,假設我們要登錄 2 個不同的用戶。該"shiny"和"shinymanager"你可以從我給的憑證看到。我希望每個人都登錄到不同版本的應用程式。一個應該看到現在顯示的 selectInput 和表,另一個是注釋掉的。也許有一種與shinymanager包裝不同的方式。
# define some credentials
credentials <- data.frame(
user = c("shiny", "shinymanager"), # mandatory
password = c("azerty", "12345"), # mandatory
start = c("2019-04-15"), # optinal (all others)
expire = c(NA, "2019-12-31"),
admin = c(FALSE, TRUE),
comment = "Simple and secure authentification mechanism
for single ‘Shiny’ applications.",
stringsAsFactors = FALSE
)
library(shiny)
library(shinymanager)
ui <- fluidPage(
tags$h2("My secure application"),
selectInput("variable", "Variable:",
c("Cylinders" = "cyl",
"Transmission" = "am",
"Gears" = "gear")),
tableOutput("data")
#selectInput("variable2", "Variable:",
# c("Cylinders" = "cyl"
# )),
#tableOutput("data2")
)
# Wrap your UI with secure_app
ui <- secure_app(ui)
server <- function(input, output, session) {
# call the server part
# check_credentials returns a function to authenticate users
res_auth <- secure_server(
check_credentials = check_credentials(credentials)
)
output$data <- renderTable({
mtcars[, c("mpg", input$variable), drop = FALSE]
}, rownames = TRUE)
#output$data2 <- renderTable({
# mtcars[, c("mpg", input$variable2), drop = FALSE]
#}, rownames = TRUE)
# your classic server logic
}
shinyApp(ui, server)
uj5u.com熱心網友回復:
使用 Shinymanager 執行此操作的一種可能方法如下。可以在此處找到另一個自構建解決方案,在github上有更多解釋。
評論中關于在 Shiny 中自建身份驗證的參考當然是正確的:使用 Shiny 之外的方法是更好的方法。
# define some credentials
credentials <- data.frame(
user = c("shiny", "shinymanager"), # mandatory
password = c("azerty", "12345"), # mandatory
start = c("2019-04-15"), # optinal (all others)
expire = c(NA, NA),
admin = c(FALSE, TRUE),
comment = "Simple and secure authentification mechanism
for single ‘Shiny’ applications.",
stringsAsFactors = FALSE
)
library(shiny)
library(shinymanager)
ui <- fluidPage(
tags$h2("My secure application"),
uiOutput("myinput"),
tableOutput("data")
)
# Wrap your UI with secure_app
ui <- secure_app(ui)
server <- function(input, output, session) {
# call the server part
# check_credentials returns a function to authenticate users
res_auth <- secure_server(
check_credentials = check_credentials(credentials)
)
output$myinput <- renderUI({
if (reactiveValuesToList(res_auth)$user == "shiny") {
# if (TRUE) {
mychoices <- c("Cylinders" = "cyl",
"Transmission" = "am",
"Gears" = "gear")
} else {
mychoices <- c("Sepal Length" = "Sepal.Length",
"Sepal Width" = "Sepal.Width",
"Petal Length" = "Petal.Length",
"Petal Width" = "Petal.Width")
}
selectInput("variable",
"Variable:",
choices = mychoices)
})
output$data <- renderTable({
expr = if (reactiveValuesToList(res_auth)$user == "shiny") {
mtcars[, c("mpg", input$variable), drop = FALSE]
} else {
iris[, c("Species", input$variable), drop = FALSE]
}
})
}
shinyApp(ui, server)
轉載請註明出處,本文鏈接:https://www.uj5u.com/net/394676.html
上一篇:從具有多個相同符號的字串中提取段
下一篇:填充/完成/按列展開
