Closed Raymond-KT closed 3 years ago
this is the comment about the error
tagAssert(header, type = "header", class = "main-header")
Hello, try calling auth_ui
module somewhere in dashboardBody
.
V
Hello!! thank you for your kindness, but I can't understand your advie TT
here is a simple example, could you explain again with this code?
library(shiny) library(shinymanager) library(shinydashboard)
credentials <- data.frame( user = c("fanny", "victor"), password = c(scrypt::hashPassword("azerty"), scrypt::hashPassword("12345")), is_hashed_password = TRUE, comment = c("alsace", "auvergne"), stringsAsFactors = FALSE )
ui <- dashboardPage( auth_ui( id = "auth",
tags_top =
tags$div(
tags$h4("Demo", style = "align:center"),
tags$img(
src = "https://www.r-project.org/logo/Rlogo.png", width = 100
)
),
# add information on bottom ?
tags_bottom = tags$div(
tags$p(
"For any question, please contact ",
tags$a(
href = "mailto:someone@example.com?Subject=Shiny%20aManager",
target="_top", "administrator"
)
)
),
# change auth ui background ?
# https://developer.mozilla.org/fr/docs/Web/CSS/background
background = "linear-gradient(rgba(0, 0, 255, 0.5),
rgba(255, 255, 0, 0.5)),
url('https://www.r-project.org/logo/Rlogo.png');",
choose_language = TRUE
),
dashboardHeader(), dashboardSidebar(), dashboardBody() )
server <- function(input, output) {
res_auth <- secure_server( check_credentials = check_credentials(credentials))
}
ui <- secure_app(ui)
shinyApp(ui, server)
I get an error code like this.
Error in tagAssert(header, type = "header", class = "main-header") : Expected an object with class 'shiny.tag'.
dashboardPage
has a fixed number of arguments, first one must be a dashboardHeader
, second one a dashboardSidebar
, etc..
So you cannot use auth_ui
here.
But if you use secure_app
you do not need auth_ui
at all :
library(shiny)
library(shinymanager)
library(shinydashboard)
credentials <- data.frame(
user = c("fanny", "victor"),
password = c(scrypt::hashPassword("azerty"), scrypt::hashPassword("12345")),
is_hashed_password = TRUE,
comment = c("alsace", "auvergne"),
stringsAsFactors = FALSE
)
ui <- dashboardPage(
dashboardHeader(),
dashboardSidebar(),
dashboardBody(
tags$div("Normal body content")
)
)
server <- function(input, output) {
res_auth <- secure_server(
check_credentials = check_credentials(credentials))
}
ui <- secure_app(ui)
shinyApp(ui, server)
auth_ui
is just a module displaying an interface with login prompt, it's included in secure_app
which contain the mechanism to secure access to the application. You can still use auth_ui
in an application but dont do it with secure_app
, otherwise you'll be asking user to enter user/pwd twice.
I'm really thank you for your kindness!!!! TT
actually, I want to custom displaying an interface with login prompt through auth_ui,
I'll try to use auth_ui without secure_app!!!
In that case you can try:
library(shiny)
library(shinymanager)
library(shinydashboard)
credentials <- data.frame(
user = c("fanny", "victor"),
password = c(scrypt::hashPassword("azerty"), scrypt::hashPassword("12345")),
is_hashed_password = TRUE,
comment = c("alsace", "auvergne"),
stringsAsFactors = FALSE
)
ui <- dashboardPage(
dashboardHeader(),
dashboardSidebar(),
dashboardBody(
auth_ui(
id = "auth",
# add image on top ?
tags_top =
tags$div(
tags$h4("Demo", style = "align:center"),
tags$img(
src = "https://www.r-project.org/logo/Rlogo.png", width = 100
)
),
# add information on bottom ?
tags_bottom = tags$div(
tags$p(
"For any question, please contact ",
tags$a(
href = "mailto:someone@example.com?Subject=Shiny%20aManager",
target="_top", "administrator"
)
)
)
),
tags$div("Normal body content")
)
)
server <- function(input, output) {
auth <- callModule(
module = auth_server,
id = "auth",
check_credentials = check_credentials(credentials)
)
}
shinyApp(ui, server)
Oh!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
I spend a lot of time for fix this problem!!!
I owe you my life!!!!!
thank you thank you!!
I just pressed the star button of your repository!!!
I want to use auth_ui background with shinydashboard. But It's not working.
when I use auth_ui with ui<- fluidepage(), It's working. But It's not working with ui<-dashboardpage()
Is there a solution to custom auth_ui with shinydashboard?
credentials <- data.frame( user = c("####", "###"), password = c("####", "####"), admin = c(T, F), stringsAsFactors = FALSE)
ui <- dashboardPage(skin='black',
. . . )
server <- function(input, output, session){
res_auth <- secure_server( check_credentials = check_credentials(credentials)) . . . }