I am trying to insert footer in shiny app dashboard in bottom and centre of the page. But it is coming in the centre of the body. Also I am unable to place it in the bottom of the page
Here is my code:
library(shiny)
library(shinydashboard)
library(DT)
library(ggvis)
library(shiny)
ui <- dashboardPage(
dashboardHeader(title = "Dashboard"),
dashboardSidebar(sidebarMenu(
menuItem("Instructions", tabName = "genIns", icon = icon("info-circle")),
menuItem("Data", tabName = "data", icon = icon("table"))
)),
dashboardBody(
tabItems(
# First tab content
tabItem(tabName = "genIns",
fluidPage(
titlePanel("General Instruction will go here"))
),
# Second tab content
tabItem(tabName = "data",
sliderInput("bins",
"Number of bins:",
min = 1,
max = 50,
value = 30),
plotOutput("distPlot")
)
),
tags$footer("My footer", align = "center")
)
)
server.ui
shinyServer(function(input, output, session) {
output$distPlot <- renderPlot({
x <- faithful[, 2] # Old Faithful Geyser data
bins <- seq(min(x), max(x), length.out = input$bins + 1)
# draw the histogram with the specified number of bins
hist(x, breaks = bins, col = 'darkgray', border = 'white')
})
})
Background: Shiny and HTML The shinydashboard package provides a set of functions designed to create HTML that will generate a dashboard. If you copy the UI code for a dashboard page (above) and paste into the R console, it will print out HTML for the dashboard.
bs4Dash: A 'Bootstrap 4' Version of 'shinydashboard'Make 'Bootstrap 4' Shiny dashboards. Use the full power of 'AdminLTE3', a dashboard template built on top of 'Bootstrap 4' <https://github.com/ColorlibHQ/AdminLTE>. Version: 2.1.0.
sidebarLayout always takes two arguments: sidebarPanel function output. mainPanel function output.
You can wrap dashbordPage
into tagList
and then place tags$footer
as a second argument to tagList
. You can also further modify the style of your footer with css.
Full example:
library(shiny)
library(shinydashboard)
library(DT)
library(ggvis)
library(shiny)
ui <- tagList(
dashboardPage(
dashboardHeader(title = "Dashboard"),
dashboardSidebar(sidebarMenu(
menuItem("Instructions", tabName = "genIns", icon = icon("info-circle")),
menuItem("Data", tabName = "data", icon = icon("table"))
)),
dashboardBody(
tabItems(
# First tab content
tabItem(tabName = "genIns",
fluidPage(
titlePanel("General Instruction will go here"))
),
# Second tab content
tabItem(tabName = "data",
sliderInput("bins",
"Number of bins:",
min = 1,
max = 50,
value = 30),
plotOutput("distPlot")
)
)
)
),#end dashboardPage
tags$footer("My footer", align = "center", style = "
position:absolute;
bottom:0;
width:100%;
height:50px; /* Height of the footer */
color: white;
padding: 10px;
background-color: black;
z-index: 1000;")
)#end tagList
server <- shinyServer(function(input, output, session) {
output$distPlot <- renderPlot({
x <- faithful[, 2] # Old Faithful Geyser data
bins <- seq(min(x), max(x), length.out = input$bins + 1)
# draw the histogram with the specified number of bins
hist(x, breaks = bins, col = 'darkgray', border = 'white')
})
})
shinyApp(ui, server)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With