Run
Run

Reputation: 57206

Shiny layout - how to add footer disclaimer?

How can I add footer notes or disclaimer in Shiny's UI? This is my current layout,

shinyUI(
  pageWithSidebar(

    headerPanel("My Title"),

    sidebarPanel("sidebar"),

    mainPanel("hello world")
)
)

I have checked this page but no mention of this. Any ideas?

What I need is,

My Title

sidebar   hello world (plots)

----------------------------

      disclaimer

Upvotes: 11

Views: 16077

Answers (2)

Dylan_Gomes
Dylan_Gomes

Reputation: 2242

I prefer to use tags$footer for this (which removes the need to have a separate .html file):

  tags$footer(strong("Disclaimer"), # strong() = bold
        align = "center", 
        style = "
                 position:fixed;
                 bottom:11.5px;
                 width:50%;
                 height:20px; 
                 color: black;
                 padding: 0px;
                 background-color: lightgrey;
                 z-index: 100;
                "),

If you add this code within mainPanel(), it will show up on every tabPanel() within. If you add it within tabPanel(), it will show up on just that tab.

Upvotes: 1

micstr
micstr

Reputation: 5206

Here is an example for other Shiny happy people to use.

Note that I have updated the above example to sidebarLayout as ?pageWithSidebar help states:

pageWithSidebar - This function is deprecated. You should use fluidPage along with sidebarLayout to implement a page with a sidebar.

Basic example of footer

I have made example the all in one app.r style so people can test this, but if you have a ui.R file just add a row just before end of your fluidPage call. I use a horizontal rule (hr) just before the footer to make the footer stand out, but this is up to you. I notice navbarPage has a header and footer parameter you can set.

# app.R
library(shiny)

ui<- shinyUI(
    fluidPage(
        title = "Footer example App",
        sidebarLayout(
            sidebarPanel(
                "sidebar",
                selectInput(
                    "pet",
                    "Pet", 
                    c("Cat", "Dog", "Fish")
                )
            ),
            mainPanel("hello world")
        ),
        # WHERE YOUR FOOTER GOES
        hr(),
        print("~~~my disclaimer~~~~")
    )
)

server <- function(input, output) {
  # empty for minimal example
}

shinyApp(ui=ui, server = server)

Result

FooterInBrowser

More advanced using footer.html

I have my own footer.html file with css and logo stylings. Place your footer.html file in your same place as your shiny files and use includeHTML. I wrap with a div so any css gets picked up.

In above example, replace line:

    print("~~~my disclaimer~~~~")

With:

    div(
        class = "footer",
        includeHTML("footer.html")
    )

EDIT: This is what my footer.html file looks like:

<!-- R Shiny
# https://github.com/rstudio/shiny-examples/blob/master/048-including-html-text-and-markdown-files/include.html
# In R Shiny use:
# includeHTML("include.html")
-->

<footer class="footer"> 
    Copyright &copy; 2021-2022 <a href="http://mycompanyurl.com">MY COMPANY NAME</a>
</footer>

Upvotes: 12

Related Questions