background color in a box in shinydashboard - css

I want to use a custom color for box in shinydashboard. the following css does the trick, but when I have the collapsible = TRUE it does not looks consistant :
library(shiny)
library(shinydashboard)
library(shinydashboardPlus)
shinyApp(
ui = dashboardPage(
dashboardHeader(),
dashboardSidebar(),
dashboardBody(
tags$style(HTML("
.box.box-solid.box-success>.box-header {
color:#2071B5;
background:#ABD7E9
}
.box.box-solid.box-success{
border-bottom-color:#ABD7E9;
border-left-color:#ABD7E9;
border-right-color:#ABD7E9;
border-top-color:#ABD7E9;
background:#ABD7E9
}
")),
box(
title = "Shiny Box",
status = "success",
solidHeader = TRUE,
collapsible = TRUE,
collapsed = TRUE,
tags$head(tags$style(HTML("div#inline label { width: 52%; }
div#inline input { display: inline-block; width: 68%;}"))),
tags$head(
tags$style(type="text/css", "#inline label{ display: table-cell; text-align: left; vertical-align: middle; }
#inline .form-group { display: table-row;}")),
div(id="inline", style="width:35vw;",
div(HTML("<b>TEST </b>")),
br(),
numericInputIcon("A", h5("test1"), value = 20, icon = icon("percent")) ,
numericInputIcon("B", h5("test2"), value = 40, icon = icon("percent")) ,
numericInputIcon("C", h5("test3"), value = 60, icon = icon("percent")) ,
currencyInput("X", "Total", value = 0.3, format = "percentageUS2dec")
)
)
)
),
server = function(input, output) { }
)
Adding the following CSS did not help as well :
.box.box-solid.box-success>.box-header>.box-tools.pull-right {
color:#2071B5;
background:#ABD7E9
}
I would like to have all the background color as #ABD7E9 including the numericinput backgrounds !

Since the parent div (with class box) has the bg color #ABD7E9, we can simply set the bg color as transparent of the elements with class form-control and classe input-group-addon to get the consistent bg color for whole box.
library(shiny)
library(shinydashboard)
library(shinydashboardPlus)
library(shinyWidgets)
shinyApp(
ui = dashboardPage(
dashboardHeader(),
dashboardSidebar(),
dashboardBody(
tags$style(
HTML(
"
.box.box-solid.box-success>.box-header {
color: #2071B5;
background:#ABD7E9;
}
.box.box-solid.box-success {
border-bottom-color:#ABD7E9;
border-left-color:#ABD7E9;
border-right-color:#ABD7E9;
border-top-color:#ABD7E9;
background: #ABD7E9;
}
.box .btn-success {
background: #ABD7E9;
}
.box .form-control,
.box .input-group-addon {
background-color: transparent;
border: transparent;
}
"
)
),
box(
title = "Shiny Box",
status = "success",
solidHeader = TRUE,
collapsible = TRUE,
collapsed = TRUE,
tags$head(tags$style(
HTML(
"div#inline label { width: 52%; }
div#inline input { display: inline-block; width: 68%;}"
)
)),
tags$head(
tags$style(
type = "text/css",
"#inline label{ display: table-cell; text-align: left; vertical-align: middle; }
#inline .form-group { display: table-row;}"
)
),
div(
id = "inline",
style = "width:35vw;",
div(HTML("<b>TEST </b>")),
br(),
numericInputIcon(
"A",
h5("test1"),
value = 20,
icon = icon("percent")
) ,
numericInputIcon(
"B",
h5("test2"),
value = 40,
icon = icon("percent")
) ,
numericInputIcon(
"C",
h5("test3"),
value = 60,
icon = icon("percent")
) ,
currencyInput("X", "Total", value = 0.3, format = "percentageUS2dec")
)
)
)
),
server = function(input, output) {
}
)

Related

Inline aligment for input label in shiny app

I want to have my numericInputIcon labels inline with the input boxes, and at the same time have the labels like the main and sub categories :
library(shiny)
library(shinyWidgets)
library(shinydashboard)
library(shinydashboardPlus)
shinyApp(
ui = dashboardPage(
dashboardHeader(),
dashboardSidebar(),
dashboardBody(
tags$head(tags$style(HTML("div#inline label { width: 52%; }
div#inline input { display: inline-block; width: 68%;}"))),
tags$head(
tags$style(type="text/css", "#inline label{ display: table-cell; text-align: left; vertical-align: middle; }
#inline .form-group { display: table-row;}")),
box(
title = "Shiny Box",
status = "success",
solidHeader = TRUE,
div(id="inline", style="width:35vw;",
div(HTML("<b>TEST </b>")),
br(),
column(12,
numericInputIcon("A", h5("test1"), value = 20, icon = icon("percent"))) ,
column(12,offset = 1,
numericInputIcon("B", h5("test1A"), value = 40, icon = icon("percent")) ,
numericInputIcon("C", h5("test1AA"), value = 60, icon = icon("percent"))) ,
column(12,
numericInputIcon("D", h5("test2"), value = 20, icon = icon("percent"))) ,
column(12,offset = 1,
numericInputIcon("E", h5("test2A"), value = 40, icon = icon("percent")) ,
numericInputIcon("F", h5("test2AA"), value = 60, icon = icon("percent"))) ,
currencyInput("X", "Total", value = 0.3, format = "percentageUS2dec")
)
)
)
),
server = function(input, output) { }
)
How should I correct the code to have all the input boxes aligned in one column ?!
Instead of using offset add a class to the subcategory h5 tags which could be used to set the left margin for the label without affecting the placement of the input box. In the code below I added a class indent and set left margin via h5.indent {margin-left: 40px}.
library(shiny)
library(shinydashboard)
library(shinydashboardPlus)
library(shinyWidgets)
shinyApp(
ui = dashboardPage(
dashboardHeader(),
dashboardSidebar(),
dashboardBody(
tags$head(tags$style(HTML("div#inline label { width: 52%; }
div#inline input { display: inline-block; width: 68%;}"))),
tags$head(
tags$style(type="text/css",
"
#inline label{ display: table-cell; text-align: left; vertical-align: middle; }
#inline .form-group { display: table-row;}
h5.indent {margin-left: 40px}
")),
box(
title = "Shiny Box",
status = "success",
solidHeader = TRUE,
div(id="inline", style="width:35vw;",
div(HTML("<b>TEST </b>")),
br(),
column(12,
numericInputIcon("A", h5("test1"), value = 20, icon = icon("percent"))) ,
column(12,
numericInputIcon("B", h5("test1A", class = 'indent'), value = 40, icon = icon("percent")) ,
numericInputIcon("C", h5("test1AA", class = 'indent'), value = 60, icon = icon("percent"))) ,
column(12,
numericInputIcon("D", h5("test2"), value = 20, icon = icon("percent"))) ,
column(12,
numericInputIcon("E", h5("test2A", class = 'indent'), value = 40, icon = icon("percent")) ,
numericInputIcon("F", h5("test2AA", class = 'indent'), value = 60, icon = icon("percent"))) ,
currencyInput("X", "Total", value = 0.3, format = "percentageUS2dec")
)
)
)
),
server = function(input, output) { }
)

Clear textinput post clicking the button

Is there a way to clear the tectinput after clicking the button. I tried with below code but does not work.
Open the application and fill the textinput. But after clicking the button, it does not clear
library(shiny)
library(shinyjs)
runApp(
list(
ui = shinyUI(fluidPage(theme = "bootstrap.css",
fluidRow(
column(8, align="center", offset = 2,
# selectInput("sdf","Asdf", choices = c(1,2), selected = NULL),
textInput("string", label="Input",value = "", width = "100%"),
tags$style("#string { height: 50px; width: 100%; text-align:center; font-size: 15px; display: block;}")
)
),
fluidRow(
column(6, align="center", offset = 3,
actionButton("button",label = "Clear"),
tags$style(type='text/css', "#button { vertical-align: middle; height: 50px; width: 100%; font-size: 30px;}")
)
)
)
), server = shinyServer(function(input, output) {
observeEvent(input$button,{
shinyjs::runjs("document.getElementById('string').reset();")
})
})))
What about updateTextInput?:
library(shiny)
library(shinyjs)
runApp(list(ui = shinyUI(
fluidPage(theme = "bootstrap.css",
fluidRow(
column(
8,
align = "center",
offset = 2,
# selectInput("sdf","Asdf", choices = c(1,2), selected = NULL),
textInput(
"string",
label = "Input",
value = "",
width = "100%"
),
tags$style(
"#string { height: 50px; width: 100%; text-align:center; font-size: 15px; display: block;}"
)
)
),
fluidRow(
column(
6,
align = "center",
offset = 3,
actionButton("button", label = "Clear"),
tags$style(
type = 'text/css',
"#button { vertical-align: middle; height: 50px; width: 100%; font-size: 30px;}"
)
)
))
), server = shinyServer(function(input, output, session) {
observeEvent(input$button, {
updateTextInput(session, inputId = "string", value = "")
})
})))

Change borders' color, length and distance from label in a shiny widget using css

I have the shiny app below in which I use css to change the borders' color of the shiny widget to red and also change the length of the input and its distance from its label "Name". But despite some of the parameters I have given in css part work, those mentioned above do not. Here is what needs to be done.
library(shiny)
library(shinydashboard)
library(shinydashboardPlus)
library(shinyjs)
css <-
"
.container {
margin: 20px;
padding: 15px;
}
#expr-container .selectize-input {
font-size: 44px;
line-height: 44px;
color: blue;
border-color: red;
width: 300px;
}
#expr-container .selectize-dropdown {
font-size: 16px;
line-height: 22px;
}
#expr-container .selectize-dropdown-content {
max-height: 5px;
padding: 0;
}
#expr-container .selectize-dropdown-content .option {
border-bottom: 1px dotted #ccc;
}
#expr-container label{
display: table-cell;
text-align: center;
vertical-align: middle;
}
#expr-container .form-group {
display: table-row;
}
"
mytitle <- paste0("Life, Death & Statins")
dbHeader <- dashboardHeaderPlus(
titleWidth = "0px",
tags$li(a(
div(style="display: inline;padding: 0px 0px 0px 0px;vertical-align:top; width: 150px;", actionButton("conse", "Consent",style=" background-color: #faf0e6; border-color: #faf0e6"))
),
class = "dropdown")
)
shinyApp(
ui = dashboardPagePlus(
header = dbHeader,
sidebar = dashboardSidebar(width = "0px",
sidebarMenu(id = "sidebar", # id important for updateTabItems
menuItem("Consent", tabName = "conse", icon = icon("line-chart"))
) ),
body = dashboardBody(
useShinyjs(),
tags$script(HTML("$('body').addClass('fixed');")),
tags$head(tags$style(".skin-blue .main-header .logo { padding: 0px;}")),
tabItems(
tabItem("conse",
fluidRow(column(1,),column(3,
tags$style(css),
tags$div(id = "expr-container",textInput("name", label = ("Name"), value = ""))))
)
)
)
),
server<-shinyServer(function(input, output,session) {
hide(selector = "body > div > header > nav > a")
}
)
)
Perhaps you are looking for this:
css <-
"
#expr-container .form-control {
background-color: transparent;
border: 3px solid black;
color: blue;
}
"
mytitle <- paste0("Life, Death & Statins")
dbHeader <- dashboardHeaderPlus(
titleWidth = "0px",
tags$li(a(
div(style="display: inline;padding: 0px 0px 0px 0px;vertical-align:top; width: 150px;", actionButton("conse", "Consent",style=" background-color: #faf0e6; border-color: #faf0e6"))
),
class = "dropdown")
)
shinyApp(
ui = dashboardPagePlus(
header = dbHeader,
sidebar = dashboardSidebar(width = "0px",
sidebarMenu(id = "sidebar", # id important for updateTabItems
menuItem("Consent", tabName = "conse", icon = icon("line-chart"))
) ),
body = dashboardBody(
useShinyjs(),
tags$script(HTML("$('body').addClass('fixed');")),
tags$head(tags$style(".skin-blue .main-header .logo { padding: 0px;}")),
tabItems(
tabItem("conse",
fluidRow(column(2,paste("Name: ")),
#column(1,),
column(5, #textInput("name", label = NULL, value = "", width="100%")
tags$style(css),
tags$div(id = "expr-container", textInput("name", label = NULL, value = "", width="100%") )
))
)
)
)
),
server<-shinyServer(function(input, output,session) {
hide(selector = "body > div > header > nav > a")
}
)
)

Customize the text Input for getting the user name and password in R Shiny

I am currently developing a shiny application. I need to have a login module at the beginning of the application. I have a desired output.
But I don't get the output as shown above.
This is the code used in ui.R
library(shiny)
library(shinyWidgets)
shinyUI(
fluidPage(
setBackgroundColor(color = "#29667a"),
fluidRow(
column(8, align = "center", offset = 2,
textInput("name", label = " ", value = " ",width = "45%"),
tags$style(type="text/css", "#string { height: 50px; width: 100%; text-align:center;
font-size: 30px; display: block;}")
)
),
fluidRow(
column(8, align = "center", offset = 2,
textInput("password", label = " ", value = " ",width = "45%"),
tags$style(type="text/css", "#string { height: 50px; width: 100%; text-align:center;
font-size: 30px; display: block;}")
)
),
fluidRow(
column(6, align = "center", offset = 3,
actionButton("login",label = "Login", width = "60%")),
tags$style(type = 'text/css',"#button { vertical-align: middle; height: 50px;
width: 100%; font-size: 30px;}"))
)
)
Can anyone say how to add the icons to the username and password boxes and have an hyperlink at the bottom of the action button. In addition to it, the input boxes are to be displayed at the middle of the page. But it gets displayed at the top of the page.
Please give a solution for this requirements.
Thanks in advance!!
Updated Answer. Based on the comment. The source code of shinyWidgets has been used to create a custom function that accepts both Icon and Password.
library(shiny)
library(shinyWidgets)
library(fontawesome)
## Modifying inbuilt textInputAddon to accept password of shinyWidgets
## blantantly copied: https://github.com/dreamRs/shinyWidgets/blob/master/R/utils.R
`%AND%` <- function (x, y) {
if (!is.null(x) && !anyNA(x))
if (!is.null(y) && !anyNA(y))
return(y)
return(NULL)
}
## blantantly copied: https://github.com/dreamRs/shinyWidgets/blob/master/R/input-textaddon.R
passwordInputAddon <- function (inputId, label, value = "", placeholder = NULL, addon, width = NULL)
{
value <- shiny::restoreInput(id = inputId, default = value)
htmltools::tags$div(
class = "form-group shiny-input-container",
label %AND% htmltools::tags$label(label, `for` = inputId),
style = if (!is.null(width)) paste0("width: ", htmltools::validateCssUnit(width), ";"),
htmltools::tags$div(
style = "margin-bottom: 5px;", class="input-group",
addon %AND% htmltools::tags$span(class="input-group-addon", addon),
htmltools::tags$input(
id = inputId, type = "password", class = "form-control",
value = value, placeholder = placeholder
)
)
)
}
ui <- shinyUI(
fluidPage(
tags$style(".container-fluid {margin-top: 20%}"),
setBackgroundColor(color = "#29667a"),
fluidRow(
column(8, align = "center", offset = 2,
textInputAddon("name", label = "", placeholder = "Username", addon = icon("user"),width = "45%"),
tags$style(type="text/css", "#string { height: 50px; width: 100%; text-align:center;
font-size: 30px; display: block;}")
)
),
fluidRow(
column(8, align = "center", offset = 2,
passwordInputAddon("password", label = "", placeholder = "Password", addon = icon("key"),width = "45%"), tags$style(type="text/css", "#string { height: 50px; width: 100%; text-align:center;
font-size: 30px; display: block;}")
)
),
fluidRow(
column(6, align = "center", offset = 3,
actionButton("login",label = "Login", width = "60%")) ),
fluidRow(
column(6, align = "center", offset = 3,
tags$div(HTML("<a href='https://www.github.com'> Forgot Password? </a>"))
))
)
)
server <- function(input, output){
}
shinyApp(ui,server)

Background color is cut in shinydashboard body

I have several boxes that will be filled with plots and tables after user input.
Since I have changed the layout to be column-based, the background color seem to be cut under the first box like this:
I am not sure why is this happening.
Here is a sample code to reproduce the layout:
library(shiny)
library(shinydashboard)
sidebar <- dashboardSidebar(
sidebarMenu(
busyIndicator(text="Loading..."),
tags$head(
tags$style(
HTML('
#uploadfile{height: 25px}
#rat{height: 25px; font-size: 10px}
#pnum{height: 25px; font-size: 10px}
#mytext{width: 50px}
.content-wrapper,
.right-side {
background-color: #EBE5D0;
}
li { cursor: pointer; cursor: hand; }
')
)
),
menuItem("Network", icon = icon("table"), tabName = "network", badgeColor = "green")
)
)
body <- dashboardBody(
tabItems(
tabItem(tabName = "network",
column( width = 2,
box(
title="INPUT FILES",solidHeader = TRUE, status="primary",
fileInput('file1',"file 1", multiple=F,accep=".Rdata"),
fileInput('file2',"file 2", multiple=F,accep=".Rdata"),
fileInput('file3',"file 3", multiple=F,accep=".Rdata"),
fileInput('file4',"file 4", multiple=F,accep=".Rdata"),
uiOutput("phenoselect"),
uiOutput("phenolog"),
tags$div(align = 'left',
class = 'multicol', uiOutput("covarselect")),
uiOutput("snpPlotButton"),
height = 800,
width = NULL
)
),
column(width = 8,
box(
title="PLOT",solidHeader = TRUE, status="primary",
plotOutput('plotSNPmaf',height="500px"),
height = 800,
width = NULL
),
box(
title="TABLE",solidHeader = TRUE, status="primary",
dataTableOutput("seqMetaGene"),
uiOutput("BoxPlotButton"),
width = NULL
),
box(
title="BOXPLOT",solidHeader = TRUE, status="primary",
plotOutput("boxplotSnps"),
width = NULL
)
)
)
))
ui<- dashboardPage(
dashboardHeader(title = "Results"),
sidebar,
body
)
server <- function(input, output,session) {}
shinyApp(ui = ui, server = server)
You need to wrap your columns in a fluidRow, this way it will work.
Like this:
fluidRow(column( ... ),
column( ... ))
Screenshot of the working example:
Using this code you can set the background color. You just have to find the color that matches.
dashboardBody(
tags$head(tags$style(HTML('
.skin-blue .left-side, .skin-blue .wrapper {
background-color: #ecf0f5;
}
')))

Resources