10:00
November 13, 2024
bslib
which is a package that provides a modern UI toolkit for Shiny and R Markdown based on Bootstraplibrary(shiny)
library(bslib)
ui <- page_navbar(
theme = bs_theme(version = 5),
title = "Modular App Blueprint",
nav_panel(
title = "Numbers",
numericInput(inputId = "number",
label = "Enter a number",
value = 0),
actionButton(inputId = "button",
label = "Click me"),
textOutput(outputId = "text")
)
)
server <- function(input, output, session) {
output$text <- renderText({
input$number^2
}) |> bindEvent(input$button)
}
shinyApp(ui, server)
Use the bootswatch
argument to change the theme (other bootswatch themes:
library(shiny)
library(bslib)
ui <- page_navbar(
theme = bs_theme(version = 5, bootswatch = "minty"),
title = "Modular App Blueprint",
nav_panel(
title = "Numbers",
numericInput(inputId = "number",
label = "Enter a number",
value = 0),
actionButton(inputId = "button",
label = "Click me"),
textOutput(outputId = "text")
)
)
server <- function(input, output, session) {
output$text <- renderText({
input$number^2
}) |> bindEvent(input$button)
}
shinyApp(ui, server)
You can also customize the theme:
library(shiny)
library(bslib)
custom_theme <- bs_theme(
version = 5,
bg = "#F9F9F9",
fg = "#003f5c",
primary = "#bc5090",
secondary = "#58508d",
warning = "#ffa600",
danger = "#ff6361",
info = "#0091d5",
base_font = font_google("PT Sans")
)
ui <- page_navbar(
theme = custom_theme,
title = "Modular App Blueprint",
nav_panel(
title = "Numbers",
numericInput(inputId = "number",
label = "Enter a number",
value = 0),
actionButton(inputId = "button",
label = "Click me",
width = "100px"),
textOutput(outputId = "text")
)
)
server <- function(input, output, session) {
output$text <- renderText({
input$number^2
}) |> bindEvent(input$button)
}
shinyApp(ui, server)
bslib
10:00
shinydashboard
package