bs4Dash
bs4Dash copied to clipboard
DashboardHeader disable = TRUE doesnt work
I am trying to disable the header component the dashboard. The code below is my attempt in doing so, using the arg disable=TRUE. However, this code fails as the header still shows.
library(shiny)
library(bs4Dash)
library(shinyWidgets)
library(shinyjs)
loginpage <- div(id = "loginpage",
bs4Card(width = 8, collapsible = FALSE, headerBorder = FALSE,
textInput("userName", placeholder="Username", label = tagList(icon("user"), "Username")),
passwordInput("passwd", placeholder="Password", label = tagList(icon("unlock-alt"), "Password")),
br(),
div(
style = "text-align: center;",
actionButton("login", "SIGN IN", width = '100%', style = "color: white; background-color:#000000;"),
shinyjs::hidden(
div(id = "nomatch", tags$p("Oops! Incorrect username or password!",
style = "color: red; font-weight: 600; padding-top: 5px;font-size:16px;",
class = "text-center"))),
br(),
))
)
ui <- dashboardPage(
dashboardHeader(id = "header", disable = TRUE, compact = TRUE),
dashboardSidebar(disable = TRUE),
dashboardBody(
useShinyjs(),
fluidRow(align = "center",
setBackgroundImage(
src = "https://www.fillmurray.com/1920/1080",
shinydashboard = TRUE),
column(width = 4, offset = 4, style = "margin: 0;position: absolute;
top: 50%;left: 50%;-ms-transform: translate(-50%, -50%);transform: translate(-50%, -50%);",
loginpage
)
)
)
)
server = function(input, output, session) {
shinyjs::hide(id = "header", anim = FALSE)
}
# Run the application
shinyApp(ui = ui, server = server)
A workaround with {htmltools}
:
library(shiny)
library(bs4Dash)
library(shinyWidgets)
library(shinyjs)
header <- dashboardHeader(compact = TRUE)
header[[1]] <- tagAppendAttributes(header[[1]], id = "header")
body <- dashboardBody(
useShinyjs(),
loginpage,
setBackgroundImage(
src = "https://www.fillmurray.com/1920/1080",
shinydashboard = TRUE
)
)
body$attribs$class <- paste(body$attribs$class, "login-page")
loginpage <- div(
id = "loginpage",
bs4Card(
width = 12, collapsible = FALSE, headerBorder = FALSE,
textInput("userName", placeholder="Username", label = tagList(icon("user"), "Username")),
passwordInput("passwd", placeholder="Password", label = tagList(icon("unlock-alt"), "Password")),
br(),
div(
style = "text-align: center;",
actionButton("login", "SIGN IN", width = '100%', style = "color: white; background-color:#000000;"),
shinyjs::hidden(
div(id = "nomatch", tags$p("Oops! Incorrect username or password!",
style = "color: red; font-weight: 600; padding-top: 5px;font-size:16px;",
class = "text-center"))),
br(),
)
)
)
ui <- dashboardPage(
header,
dashboardSidebar(disable = TRUE),
body
)
server = function(input, output, session) {
shinyjs::hide(id = "header", anim = FALSE)
}
# Run the application
shinyApp(ui = ui, server = server)
A very late reply, but maybe someone will find this useful - there is no need for {shinyjs}
. All you have to do, is to set:
header <- list(shiny::tags$nav(style = "display: none;", class = "main-header navbar navbar-expand"), NULL)
Please note that this solution does not work with sidebar enabled.
@domsle - your solution worked for me. I also had no problem with the sidebar being enabled either. Anyone else who wants to use @domsle 's solution: where he has a NULL
as the 2nd argument in his list you can replace that with bs4Dash::dashboardBrand
if you want to still keep the branding at the top of the sidebar.