Change the size of an icon in shiny dashboard - r

How can I change the size of an icon() in shiny dashboard?
library(shiny)
library(shinydashboardPlus)
shinyApp(
ui = dashboardPage(skin = "purple",
options = list(sidebarExpandOnHover = TRUE),
header = dashboardHeader(
controlbarIcon = shiny::icon("filter")
),
sidebar = dashboardSidebar(),
body = dashboardBody(
tags$style(".fa-filter {color:red;size:26px}"),
),
controlbar = dashboardControlbar(
id = "controlbar",
collapsed = FALSE,
overlay = TRUE,
skin = "light",
pinned = T
)
),
server = function(input, output, session) {
}
)

You have to set the CSS property font-size instead of size:
library(shiny)
library(shinydashboardPlus)
shinyApp(
ui = dashboardPage(
skin = "purple",
options = list(sidebarExpandOnHover = TRUE),
header = dashboardHeader(
controlbarIcon = shiny::icon("filter")
),
sidebar = dashboardSidebar(),
body = shinydashboard::dashboardBody(
tags$style(".fa-filter {color:red; font-size:26px}"),
),
controlbar = dashboardControlbar(
id = "controlbar",
collapsed = FALSE,
overlay = TRUE,
skin = "light",
pinned = T
)
),
server = function(input, output, session) {
}
)
#>
#> Listening on http://127.0.0.1:6563

Below please find two alternative ways not requiring a separate style tag:
library(shiny)
library(fontawesome)
shinyApp(
basicPage(
shiny::icon("filter", class = "fa-3x"),
fontawesome::fa("filter", height = "3em")
),
server = function(input, output, session) {
}
)
Furthermore, please check this related article.
Using your example:
library(shiny)
library(shinydashboardPlus)
shinyApp(
ui = dashboardPage(
skin = "purple",
options = list(sidebarExpandOnHover = TRUE),
header = dashboardHeader(
controlbarIcon = shiny::icon("filter", class = "fa-3x", style = "color:red;")
# controlbarIcon = fontawesome::fa("filter", height = "3em", fill = "red")
),
sidebar = dashboardSidebar(),
body = shinydashboard::dashboardBody(),
controlbar = dashboardControlbar(
id = "controlbar",
collapsed = FALSE,
overlay = TRUE,
skin = "light",
pinned = T
)
),
server = function(input, output, session) {
}
)

Related

conditionalpanel in shiny tabBox

In the following shiny app I would like to have the second tab inside the box if user selection is sh, So I was expecting the conditionalPanel command does the trick ! but it is not working:
library(shiny)
library(shinydashboard)
ui <- dashboardPage(
skin = "green",
dashboardHeader(title = "conditional tabBox"),
dashboardSidebar(
width = 250,
sidebarMenu(
id = "tabs",
radioButtons(inputId = "layout_status",
label = "",
inline = TRUE,
choices = c("Layout" = "ly","Shape file" = "sh"),
selected = "ly")
)
),
dashboardBody(
tabBox(width = 12,
tabPanel(
id = "p1",
title = HTML("<p style='color:#2071B5'><b>TAB 1</b></p>")
),
conditionalPanel(condition = " input.layout_status=='sh' ",
tabPanel(
id = "p2",
title = HTML("<p style='color:#2071B5'><b>TAB 2</b></p>")
)
)
)
)
)
server <- function(input, output) { }
shinyApp(ui, server)
tabBox expects tabPanel elements to be passed to its ... argument - conditionalPanel elements are not allowed.
However you can use hideTab / showTab instead:
library(shiny)
library(shinydashboard)
ui <- dashboardPage(
skin = "green",
dashboardHeader(title = "conditional tabBox"),
dashboardSidebar(
width = 250,
sidebarMenu(
id = "tabs",
radioButtons(inputId = "layout_status",
label = "",
inline = TRUE,
choices = c("Layout" = "ly","Shape file" = "sh"),
selected = "ly")
)
),
dashboardBody(
tabBox(
tabPanel(
value = "p1",
title = HTML("<p style='color:#2071B5'><b>TAB 1</b></p>")
),
tabPanel(
value = "p2",
title = HTML("<p style='color:#2071B5'><b>TAB 2</b></p>")
),
id = "tabBoxID", width = 12)
)
)
server <- function(input, output, session) {
observeEvent(input$layout_status, {
if(input$layout_status == 'sh'){
showTab(inputId = "tabBoxID", target = "p2", select = TRUE)
} else {
hideTab(inputId = "tabBoxID", target = "p2")
}
})
}
shinyApp(ui, server)

Change the color and icon of the gear of shinydashboard dashboardControlBar

How can someone change the color and icon of the gear of shinydashboard dashboardControlBar?
library(shiny)
shinyApp(
ui = dashboardPage(
header = dashboardHeader(),
sidebar = dashboardSidebar(),
body = dashboardBody(
#tags$style(".fa-thumbtack {color:rgb(255,0,0)}"), ## this changes only the horizontal pin color
tags$head(tags$style(type = "text/css", ".fa-thumbtack {color:rgb(255,0,0) !important;}"))
),
controlbar = dashboardControlbar(
id = "controlbar",
collapsed = FALSE,
overlay = TRUE,
skin = "light",
pinned = T
)
),
server = function(input, output, session) {
}
)
To change the color use skin = where you can set various colors: see here https://rstudio.github.io/shinydashboard/appearance.html
To change the icon of the former known "right-sidebar" now known as "controlbar" use controlbarIcon in dashboardHeader: Here we changed the gear icon with the info icon:
library(shiny)
library(shinydashboardPlus)
shinyApp(
ui = dashboardPage(skin = "purple",
options = list(sidebarExpandOnHover = TRUE),
header = dashboardHeader(
controlbarIcon = shiny::icon("info")
),
sidebar = dashboardSidebar(),
body = dashboardBody(
#tags$style(".fa-thumbtack {color:rgb(255,0,0)}"), ## this changes only the horizontal pin color
tags$head(tags$style(type = "text/css", ".fa-thumbtack {color:rgb(255,0,0) !important;}"))
),
controlbar = dashboardControlbar(
id = "controlbar",
collapsed = FALSE,
overlay = TRUE,
skin = "light",
pinned = T
)
),
server = function(input, output, session) {
}
)

How to change the color of Pined controlbar in Shiny Dashboard

Looking for a way to change the color of the pinned controlbar in shinyDashboard. I have been able to change the color of every element in the shinydashboard except for the little pin when you pin the controlbar on the right side of main page.
Any Help would be highly appreciated.
library(shiny)
library(bs4Dash)
shinyApp(
ui = dashboardPage(
header = dashboardHeader(),
sidebar = dashboardSidebar(),
body = dashboardBody(),
controlbar = dashboardControlbar(
id = "controlbar",
collapsed = FALSE,
overlay = TRUE,
skin = "light",
pinned = T
)
),
server = function(input, output, session) {
}
)
To change the thumb-tack color, you can use
tags$head(tags$style(type = "text/css", ".fa-thumbtack {color:rgb(255,0,0) !important;}"))
Full code
library(shiny)
library(bs4Dash)
shinyApp(
ui = dashboardPage(
header = dashboardHeader(),
sidebar = dashboardSidebar(),
body = dashboardBody(
#tags$style(".fa-thumbtack {color:rgb(255,0,0)}"), ## this changes only the horizontal pin color
tags$head(tags$style(type = "text/css", ".fa-thumbtack {color:rgb(255,0,0) !important;}"))
),
controlbar = dashboardControlbar(
id = "controlbar",
collapsed = FALSE,
overlay = TRUE,
skin = "light",
pinned = T
)
),
server = function(input, output, session) {
}
)

Hide and show sidebars based on chosen tabPanel in shinydashboard

I have the shinydashboard below in which I have 3 tabPanels. In the 1st tabPanel "Resource Allocation" I want the left and right sidebar open by default. In the 2nd and 3rd tabpanels ("Time Series","Longitudinal View") I want only left sidebar and the right sidebar not just hidden but to not be able to open at all by pushing the "gears" icon above it which should be removed. And in the fourth panel "User Guide" I want no sidebar and no choise to open one of them at all.
library(shiny)
library(shinydashboard)
library(shinydashboardPlus)
library(shinyjs)
shinyApp(
ui = dashboardPage(
options = list(sidebarExpandOnHover = TRUE),
header = dashboardHeader(
titleWidth = "0px"
),
sidebar = dashboardSidebar(minified = TRUE, collapsed = F),
body = dashboardBody(
useShinyjs(),#tags$head(tags$script(src="format_number.js")),
tags$script("document.getElementsByClassName('sidebar-toggle')[0].style.visibility = 'hidden';"),
tabsetPanel(
tabPanel("Resource Allocation"),
tabPanel("Time Series"),
tabPanel("Longitudinal View"),
tabPanel("User Guide")
)
),
controlbar = dashboardControlbar(collapsed = F),
title = "DashboardPage"
),
server = function(input, output) { }
)
I have a solution for the left sidebar. I am sure you can spend sometime and figure out the solution for the right sidebar. Please note that this requires some more work to fine tune to your needs. Try this
library(shiny)
library(shinydashboard)
library(shinydashboardPlus)
library(shinyjs)
library(DT)
ui <- shinydashboardPlus::dashboardPage(
options = list(sidebarExpandOnHover = TRUE),
shinydashboardPlus::dashboardHeader(
#titleWidth = "0px"
),
shinydashboardPlus::dashboardSidebar( disable = TRUE ,
sidebarMenu(
selectInput(
"countries", label = "Select Countries",
choices = c("B", "C", "A"), selected = "A",
multiple = TRUE
))
),# minified = TRUE, collapsed = F),
controlbar = shinydashboardPlus::dashboardControlbar(id = "controlbar", collapsed = F,
skin = "dark",
controlbarMenu(
id = "menu",
controlbarItem(
"Tab 1",
"Welcome to tab 1"
),
controlbarItem(
"Tab 2",
"Welcome to tab 2"
)
)
),
shinydashboard::dashboardBody(
useShinyjs(),
tabsetPanel( id="tabset",
tabPanel("Resource Allocation", value="tab1", plotOutput("plot")),
tabPanel("Time Series", value="tab2", plotOutput("plot2")),
tabPanel("Longitudinal View", value="tab3", DTOutput("ir")),
tabPanel("User Guide", value="tab4", DTOutput("mt"))
)
),
# controlbar = dashboardControlbar(collapsed = F),
title = "DashboardPage"
)
server <- function(input, output) {
output$plot <- renderPlot(plot(cars))
output$plot2 <- renderPlot(plot(pressure))
output$mt <- renderDT(mtcars)
output$ir <- renderDT(iris)
observeEvent(input[["tabset"]], {
if(input[["tabset"]] == "tab4"){
addClass(selector = "body", class = "sidebar-collapse")
updateControlbar("controlbar")
}else{
removeClass(selector = "body", class = "sidebar-collapse")
}
})
}
shinyApp(ui, server)

transposition of verticalProgress in Shiny R

have anyone seen something that we can call horizontalProgress in Shiny? I found function verticalProgress which is almost perfect for my, unfortunately I need to transposition it. Maybe how to help my? Maybe using CSS?
if (interactive()) {
library(shiny)
library(shinydashboard)
shinyApp(
ui = dashboardPagePlus(
header = dashboardHeaderPlus(
enable_rightsidebar = TRUE,
rightSidebarIcon = "gears"
),
sidebar = dashboardSidebar(),
body = dashboardBody(
verticalProgress(
value = 20,
status = "danger",
size = "xs",
height = "60%"
)
),
rightsidebar = rightSidebar(),
title = "Right Sidebar"
),
server = function(input, output) { }
)
}
You can use transform in the style :
div(style="display: inline-block; transform: rotate(10deg);",verticalProgress(
value = 20,
status = "danger",
size = "xs",
height = "60%"
))
Alternatively you can use shinyWidgets library which has progressBar
if (interactive()) {
library(shiny)
library(shinydashboard)
library(shinydashboardPlus)
library(shinyWidgets)
shinyApp(
ui = dashboardPagePlus(
header = dashboardHeaderPlus(
enable_rightsidebar = TRUE,
rightSidebarIcon = "gears"
),
sidebar = dashboardSidebar(),
body = dashboardBody(
column(2,
progressBar(id = "pb6", value = 20, status = "danger", size = "xs")
)
),
rightsidebar = rightSidebar(),
title = "Right Sidebar"
),
server = function(input, output) { }
)
}

Resources