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) { }
)
Related
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) {
}
)
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 = "")
})
})))
I am current developing a shiny application and I need to hide login page and show shiny dashboard upon successful login. If not, the login page should be displayed.
I came upon few sites and I decided to use shinyjs package for showing and hiding of the fluid page / dashboard page.
The global function used is as follows:
`%AND%` <- function (x, y) {
if (!is.null(x) && !anyNA(x))
if (!is.null(y) && !anyNA(y))
return(y)
return(NULL)
}
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
)
)
)
}
The UI code used is as follows:
ui <- shinyUI(fluidPage(
tags$div(id = "login_page_ui",
shinyjs::useShinyjs(),
tags$style(".container-fluid {margin-top: 13%}"),
setBackgroundColor(color = "#2d3c44"),
fluidRow(
column(8, align = "center", offset = 2,
textInputAddon("name", label = "", placeholder = "Username", addon = icon("user"),width = "25%"),
tags$style(type="text/css", "#string { height: 50px; width: 50%; text-align:center;
font-size: 30px; display: block;}")
)
),
fluidRow(
column(8, align = "center", offset = 2,
passwordInputAddon("password", label = "", placeholder = "Password", addon = icon("key"),width = "25%"),
tags$style(type="text/css", "#string { height: 50px; width: 50%; text-align:center;
font-size: 30px; display: block;}")
)
),
fluidRow(
column(12, div(style = "height:20px;background-color: #2d3c44;")
)
),
fluidRow(
column(6, align = "center", offset = 3,
actionButton("login",label = "Login", width = "35%", style = "color: #fff; background-color: #1bc3d7; border-color: #1bc3d7;")))
)
),
shinyjs::hidden(
tags$div(
id = "dashboard_page_ui",
dashboardPage(
dashboardHeader(
title="Shiny Dashboard",
tags$li(
class="dropdown"
)
),
dashboardSidebar(
sidebarMenu(
id = 'dashboard_menu',
sidebarMenuOutput("menu")
)
),
dashboardBody(
tabItems(
tabItem(tabName="Item1"),
tabItem(tabName="Item2"),
tabItem(tabName="Item3")
)
)
)
)
)
)
The server code used is as follows:
server <- function(input, output,session){
observeEvent(input$login,{
if((input$name == "test") & (input$password == "test123")){
shinyjs::show("dashboard_page_ui")
shinyjs::hide("login_page_ui")
}
})
}
When I execute this code I am getting this error message
Error in shinyUI(fluidPage(tags$div(id = "login_page_ui", shinyjs::useShinyjs(), :
unused argument (shinyjs::hidden .....
I don't know what's the exact issue is. Can anyone help me to sort this issue?
shinyUI takes a single argument ui (The user interace definition). However, you provided two arguments: see the comma before shinyjs::hidden(...) in your code.
Please check the following:
library(shiny)
library(shinydashboard)
`%AND%` <- function (x, y) {
if (!is.null(x) && !anyNA(x))
if (!is.null(y) && !anyNA(y))
return(y)
return(NULL)
}
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 <- fluidPage(
tags$div(
id = "login_page_ui",
shinyjs::useShinyjs(),
tags$style(".container-fluid {margin-top: 13%}"),
setBackgroundColor(color = "#2d3c44"),
fluidRow(
column(
8,
align = "center",
offset = 2,
textInputAddon(
"name",
label = "",
placeholder = "Username",
addon = icon("user"),
width = "25%"
),
tags$style(
type = "text/css",
"#string { height: 50px; width: 50%; text-align:center;
font-size: 30px; display: block;}"
)
)
),
fluidRow(
column(
8,
align = "center",
offset = 2,
passwordInputAddon(
"password",
label = "",
placeholder = "Password",
addon = icon("key"),
width = "25%"
),
tags$style(
type = "text/css",
"#string { height: 50px; width: 50%; text-align:center;
font-size: 30px; display: block;}"
)
)
),
fluidRow(column(
12, div(style = "height:20px;background-color: #2d3c44;")
)),
fluidRow(column(
6,
align = "center",
offset = 3,
actionButton(
"login",
label = "Login",
width = "35%",
style = "color: #fff; background-color: #1bc3d7; border-color: #1bc3d7;"
)
))
),
shinyjs::hidden(tags$div(
id = "dashboard_page_ui",
dashboardPage(
dashboardHeader(title = "Shiny Dashboard",
tags$li(class = "dropdown")),
dashboardSidebar(sidebarMenu(id = 'dashboard_menu',
sidebarMenuOutput("menu"))),
dashboardBody(tabItems(
tabItem(tabName = "Item1"),
tabItem(tabName = "Item2"),
tabItem(tabName = "Item3")
))
)
))
)
server <- function(input, output, session) {
observeEvent(input$login, {
if ((input$name == "test") & (input$password == "test123")) {
shinyjs::show("dashboard_page_ui")
shinyjs::hide("login_page_ui")
}
})
}
shinyApp(ui, server)
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)
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;
}
')))