How can I add boxes to shiny app without ruining page? - r

I have a shiny app that looks like this:
I would like to add a Box 3 and Box 4 beneath the mouse logo, but cannot seem to figure out how to do this without messing the page up. The result is below:
i am using two fluidRow functions to make these boxes, but I am not sure how I can keep the entire page intact while doing so. Any help is appreciated! Code is below:
#require packages
rqrd_Pkg = c('shiny','plotly','plyr','tidyverse',
'uuid', 'devtools', 'gtools', 'inline', 'shiny',
'shinydashboard', 'plotly', 'shinythemes',
'shinycssloaders', 'shinyjs',
'DT', 'tictoc',
'data.table', 'htmlwidgets')
require(shiny)
for(p in rqrd_Pkg){
if(!require(p,character.only = TRUE))
install.packages(p, Ncpus=8);
library(p,character.only = TRUE)
}
#include style for header
head.style <- "
/* old shiny progress indicators */
.shiny-progress-container {
position: fixed;
top: 0px;
width: 100%;
z-index: 4000;
}
.shiny-progress .progress-text {
color: #020202;
background-colort: #FF0000;
width: 225px;
left: calc(50% - 125px);
}
.progress-text {
/* Copy the below to vertically center the progress bar text box in the shiny dashboard header */
/* !important is crucial here otherwise it gets overridden by the dreaded element.style */
top: 15px !important;
text-align: center;
}
"
#initiate dashboard attributes and colors
dashboardPage(
skin = "purple",
dashboardHeader(
title = HTML("Title"),
dropdownMenu(type = "notifications", icon = tagList(icon("question-circle"), "Help"), badgeStatus = NULL, headerText = "Links",
tags$li(a(icon("external-link"), "XYZ", href = "http://info.com", target = "blank")),
tags$li(a(icon("external-link"), "ABC", href = "http://info.com", target = "blank")))
),
dashboardSidebar(sidebarMenu(
menuItem("Target Dashboard", tabName = "dashboard_tab", icon = icon("dashboard"))
)),
#################################################################################
#################################################################################
#################################################################################
#################################################################################
#Configure dashboard body.
dashboardBody(
tags$head(
tags$link(rel = "shortcut icon", href = "favicon.ico"),
tags$link(rel = "apple-touch-icon", sizes = "180x180", href = "favicon.ico"),
tags$link(rel = "icon", type = "image/png", sizes = "32x32", href = "favicon-32x32.png"),
tags$link(rel = "icon", type = "image/png", sizes = "16x16", href = "favicon-16x16.png"),
tags$style(head.style)
),
#h1(paste0("<b>","Gene summary:","</b>")),
titlePanel(div(HTML("<b>Gene summary</b>"), align = "left")),
tabItems(
tabItem(tabName = "dashboard_tab",
tags$style(HTML("
#first {
border: 4px double red;
}
#second {
border: 2px dashed blue;
}
")),
fluidRow(
valueBoxOutput("valueGeneName"),
valueBoxOutput("valueGeneRank"),
valueBoxOutput("gtexSpec"),
valueBoxOutput("valueHuman"),
valueBoxOutput("valueMouse"),
valueBoxOutput("valueNHP"),
valueBoxOutput("exprCompartment")
),
h2(paste0("Header 1"), align="left"),
#insert human logo
mainPanel(
img(src='man_log.png', height="10%", width="10%", align="left"),
),
#create boxes
fluidRow(
box(
title = "Box 1",
status = "primary",
solidHeader = TRUE,
collapsible = TRUE,
plotOutput("roc", height = "300px")
),
box(
title = "Box 2"
,status = "primary"
,solidHeader = TRUE
,collapsible = TRUE
,plotOutput("sensDNAProt", height = "300px")
)),
mainPanel(
img(src='mouse.png', height="10%", width="10%", align="left")
),
h2(paste0("Header 2"), align="left"),
#ADDING THIS CAUSES PROBLEMS!!!
fluidRow(
box(
title = "Box 3",
status = "primary",
solidHeader = TRUE,
collapsible = TRUE,
plotOutput("roc", height = "300px")
),
box(
title = "Box 4",
status = "primary",
solidHeader = TRUE,
collapsible = TRUE,
plotOutput("roc", height = "300px")
)
)
)
)
)
)
`

You should get the desired output with this.
### include style for header
head.style <- "
/* old shiny progress indicators */
.shiny-progress-container {
position: fixed;
top: 0px;
width: 100%;
z-index: 4000;
}
.shiny-progress .progress-text {
color: #020202;
background-colort: #FF0000;
width: 225px;
left: calc(50% - 125px);
}
.progress-text {
/* Copy the below to vertically center the progress bar text box in the shiny dashboard header */
/* !important is crucial here otherwise it gets overridden by the dreaded element.style */
top: 15px !important;
text-align: center;
}
"
#initiate dashboard attributes and colors
ui <- dashboardPage(
skin = "purple",
dashboardHeader(
title = HTML("Title"),
dropdownMenu(type = "notifications", icon = tagList(icon("question-circle"), "Help"), badgeStatus = NULL, headerText = "Links",
tags$li(a(icon("external-link"), "XYZ", href = "http://info.com", target = "blank")),
tags$li(a(icon("external-link"), "ABC", href = "http://info.com", target = "blank")))
),
dashboardSidebar(sidebarMenu(
menuItem("Target Dashboard", tabName = "dashboard_tab", icon = icon("dashboard"))
)),
#################################################################################
#################################################################################
#################################################################################
#################################################################################
#Configure dashboard body.
dashboardBody(
tags$head(
tags$link(rel = "shortcut icon", href = "favicon.ico"),
tags$link(rel = "apple-touch-icon", sizes = "180x180", href = "favicon.ico"),
tags$link(rel = "icon", type = "image/png", sizes = "32x32", href = "favicon-32x32.png"),
tags$link(rel = "icon", type = "image/png", sizes = "16x16", href = "favicon-16x16.png"),
tags$style(head.style)
),
#h1(paste0("<b>","Gene summary:","</b>")),
titlePanel(div(HTML("<b>Gene summary</b>"), align = "left")),
tabItems(
tabItem(tabName = "dashboard_tab",
tags$style(HTML("
#first {
border: 4px double red;
}
#second {
border: 2px dashed blue;
}
")),
fluidRow(width=12,
tabBox(id = "tabset1", height = "2250px", width=12, title = " ",
tabPanel(
br(),br(),
fluidRow(h2(paste0("Header 0"), align="left")),
fluidRow(
shinydashboard::valueBoxOutput("myvaluebox1", width=4),
shinydashboard::valueBoxOutput("myvaluebox2", width=4),
shinydashboard::valueBoxOutput("myvaluebox3", width=4)
),
fluidRow(
shinydashboard::valueBoxOutput("myvaluebox4", width=4),
shinydashboard::valueBoxOutput("myvaluebox5", width=4),
shinydashboard::valueBoxOutput("myvaluebox6", width=4)
),
fluidRow(
shinydashboard::infoBoxOutput("myvaluebox7", width=4),
shinydashboard::valueBoxOutput("myvaluebox8", width=4)
),
br(),
fluidRow(h2(paste0("Header 1"), align="left")),
#br(),
fluidRow(img(src='man_log.png', height="5%", width="5%", align="left")),
br(),
fluidRow(
column(6,
box( height="300px", width=NULL,
collapsible = TRUE,
title = "Box 1",
status = "primary",
solidHeader = TRUE,
plotOutput("plot1", height = "210px", width="350px")
), style='width: 500px; height: 400px' ),
column(6,
box(height="300px", width="450px",
title = "Box 2",
status = "primary",
solidHeader = TRUE,
collapsible = TRUE,
plotOutput("plot2", height = "230px", width="380px")
), style='width: 500px; height: 400px')
),
br(),# br(),
img(src='mouse.png', height="10%", width="10%", align="left"),
br(),
h2(paste0("Header 2"), align="left"),
br(),
fluidRow(
column(6,
box(height="300px", width="450px",
title = "Box 3",
status = "primary",
solidHeader = TRUE,
collapsible = TRUE,
plotOutput("plot3", height = "220px", width="350px")
), style='width: 500px; height: 400px' ),
column(6,
box(height="300px", width="450px",
title = "Box 4",
status = "primary",
solidHeader = TRUE,
collapsible = TRUE,
plotOutput("plot4", height = "220px", width="350px")
), style='width: 500px; height: 400px')
)
) ## end of tabPanel
) ## end of tabBox
)
) ## end of tabItem
)
)
)
server <- function(input, output, session){
output$plot1 <- renderPlot(qplot(rnorm(500),fill=I("red"),binwidth=0.2,title="plotgraph1"))
output$plot2 <- renderPlot(qplot(rnorm(500),fill=I("green"),binwidth=0.2,title="plotgraph2"))
output$plot3 <- renderPlot(qplot(rnorm(500),fill=I("blue"),binwidth=0.2,title="plotgraph3"))
output$plot4 <- renderPlot(qplot(rnorm(500),fill=I("orange"),binwidth=0.2,title="plotgraph4"))
output$myvaluebox1 <- shinydashboard::renderValueBox({
shinydashboard::valueBox('2000',subtitle = "blah blah blah1",icon = icon("car"),
color = "green"
)
})
output$myvaluebox2 <- shinydashboard::renderValueBox({
shinydashboard::valueBox('2001',subtitle = "blah blah blah2",icon = icon("car"),
color = "green"
)
})
output$myvaluebox3 <- shinydashboard::renderValueBox({
shinydashboard::valueBox('2002',subtitle = "blah blah blah3",icon = icon("car"),
color = "green"
)
})
output$myvaluebox4 <- shinydashboard::renderValueBox({
shinydashboard::valueBox('2009',subtitle = "blah blah blah4",icon = icon("car"),
color = "red"
)
})
output$myvaluebox5 <- shinydashboard::renderValueBox({
shinydashboard::valueBox('2010',subtitle = "XYZ1",icon = icon("car"),
color = "red"
)
})
output$myvaluebox6 <- shinydashboard::renderValueBox({
shinydashboard::valueBox('2011',subtitle = "XYZ2",icon = icon("car"),
color = "green"
)
})
output$myvaluebox7 <- shinydashboard::renderInfoBox({
shinydashboard::infoBox('2020',subtitle = "This is infobox",icon = icon("car"),
color = "blue"
)
})
output$myvaluebox8 <- shinydashboard::renderValueBox({
shinydashboard::valueBox('2021',subtitle = "This is valuebox",icon = icon("car"),
color = "blue"
)
})
}
shinyApp(ui = ui, server = server)

Related

Edit contents of Modal popup in R shiny

I would like to edit the contents of a modal popup in R shiny. Below is my code with which I'm able to print the values in the modal popup but I'm not able to edit it.
Server.R
modelnetlist <- function(failed = FALSE){
netlistdata <- readLines('run.scs')
splitText1 <- stringi::stri_split(str = netlistdata, regex = '\\n')
# wrap a paragraph tag around each element in the list
replacedText1 <- lapply(splitText1, p)
modalDialog(
title = "Netlist File",
replacedText1,
easyClose = FALSE,
footer = tagList(
modalButton("Close"),
actionButton("save", "Save")
)
)
}
observeEvent(input$gennet, {
showModal(modelnetlist())
})
ui.R
options(shiny.maxRequestSize=100*1024^2)
ui <- dashboardPage(skin = "yellow",
dashboardHeader(title = "Modelling Automation"),
dashboardSidebar(
sidebarMenu(
# Setting id makes input$tabs give the tabName of currently-selected tab
id = "tabs",
menuItem("Data Processing", tabName = "DP", icon = icon("database"), startExpanded = TRUE,
menuSubItem("Merge", tabName= "Merge"),
menuSubItem("Data", tabName = "Data"),
menuSubItem("Plot", tabName = "Plot", selected = TRUE),
menuSubItem("Parameters", tabName = "Parameters")),
menuItem("Parameter Extraction", icon = icon("book-open"), tabName = "PE"),
menuSubItem("Data Conversion", tabName = "DC"),
menuSubItem("IPL Upload", tabName = "IPL"),
menuSubItem("Netlist Spectre", tabName = "netlist"),
menuSubItem("Spectre logs", tabName = "mylog"),
menuSubItem("Parameter Fitting", tabName = "PF"),
menuItem("Model QA", tabName = "QA", icon = icon("angellist"))
),
textOutput("res")
),
dashboardBody(
tabItems(
tabItem("DP", "Dashboard tab content"),
#tabItem("PE", "Widgets tab content"),
tabItem("Merge", fileInput("mergefiles", "choose the files", accept = c(".txt"), multiple = TRUE), downloadButton("Download", label = "Merged File")),
tabItem("Data",
mainPanel(div(style='overflow-x:scroll',tableOutput("txt"),tableOutput("filetable"),tableOutput("filetable1")))
),
tabItem("Plot",sidebarLayout(sidebarPanel(width=3,
fileInput("datasets", "choose the files", accept = c(".txt",".esd"), multiple = TRUE),
uiOutput("plotdata"),uiOutput("devicetype"), uiOutput("chip"),
uiOutput("macro"),
uiOutput("device"),fluidRow(column(5,uiOutput("minIT2")),column(5,uiOutput("maxIT2"))),
fluidRow(column(5,uiOutput("temperature")), column(5,uiOutput("DCleakage"))),
fluidRow(column(5,uiOutput("varx")),column(5,uiOutput("vary")))
),
mainPanel(width=9,
plotlyOutput("PLOT")))),
tabItem("Parameters",tags$style(type="text/css",
".shiny-output-error { visibility: hidden; }",
".shiny-output-error:before { visibility: hidden; }"),
div(style="display:inline-block;width:32%;text-align: center;",actionButton("action", label = "Normalize")),
tabsetPanel(type="tabs",
tabPanel("CV Table",div(style='overflow-x:scroll',dataTableOutput('DiodeCVTable')),fluidRow(column(5, actionButton("perimeterCV", label="Change Perimeter")),column(5, actionButton("changeCV", label = "Change Goldenchip"))),fluidRow(column(5, uiOutput("dynamicCV")),column(5,uiOutput("goldenchipCV"))),plotlyOutput("cvplot")),
tabPanel("DC Table",div(style='overflow-x:scroll',dataTableOutput('DiodeDCTable')),fluidRow(column(5, actionButton("perimeterDC", label="Change Perimeter")),column(5, actionButton("changeDC", label = "Change Goldenchip"))),fluidRow(column(5, uiOutput("dynamicDC")),column(5,uiOutput("goldenchipDC"))),plotlyOutput("dcplot")),
tabPanel("TLP Table",div(style='overflow-x:scroll',dataTableOutput('TLPTable')), fluidRow(column(5, actionButton("perimeterTLP", label="Change Perimeter")),column(5, actionButton("changeTLP", label = "Change Goldenchip"))),fluidRow(column(5, uiOutput("dynamicTLP")),column(5,uiOutput("goldenchipTLP"))),plotlyOutput("tlpplot")),
tabPanel("VFTLP Table",div(style='overflow-x:scroll',dataTableOutput('VFTLPTable')), fluidRow(column(5, actionButton("perimeterVFTLP", label="Change Perimeter")),column(5, actionButton("changeVFTLP", label = "Change Goldenchip"))),fluidRow(column(5, uiOutput("dynamicVFTLP")),column(5,uiOutput("goldenchipVFTLP"))), plotlyOutput("vftlpplot")))),
tabItem("PE","Parameter Extraction Content"),
tabItem("DC",uiOutput("onedevice"),uiOutput('tabs'),
conditionalPanel(condition="input.layer=='CV'", plotlyOutput("plotcv1"),br(), tableOutput("device1cv")),
#conditionalPanel(condition="input.layer=='CV 2'", plotlyOutput("plotcv2"),br(), tableOutput("device2cv")),
# conditionalPanel(condition="input.layer=='CV 3'", plotlyOutput("plotcv3"),br(), tableOutput("device2cv")),
conditionalPanel(condition="input.layer=='DC # 25'", plotlyOutput("plotdc125"),br(), tableOutput("device1dc25")),
conditionalPanel(condition="input.layer=='DC # -40'", plotlyOutput("plotdc140"),br(), tableOutput("device1dc40")),
conditionalPanel(condition="input.layer=='DC # 125'", plotlyOutput("plotdc1125"),br(), tableOutput("device1dc125")),
conditionalPanel(condition="input.layer=='DC # 150'", plotlyOutput("plotdc1150"),br(), tableOutput("device1dc150")),
conditionalPanel(condition="input.layer=='TLP'",fluidRow(column(3,uiOutput("stepcountTLP")), column(3, uiOutput("maxvoltageTLP")), column(3, uiOutput("VholdTLP")), downloadButton("DownloadTLP",label = "Download converted data")), plotlyOutput("plottlp1"),br(), tableOutput("device1tlp")),
#conditionalPanel(condition="input.layer=='TLP 2'", plotlyOutput("plottlp2"),br(), tableOutput("device2tlp")),
conditionalPanel(condition="input.layer=='VFTLP'",fluidRow(column(3,uiOutput("stepcountVFTLP")), column(3, uiOutput("maxvoltageVFTLP")), column(3, uiOutput("VholdVFTLP"))), plotlyOutput("plotvftlp1"),br(), tableOutput("device1vftlp"))
),
tabItem("PF", uiOutput('modelingtabs'),
conditionalPanel(condition="input.modtab=='CV'",tableOutput("modelingdevice1CV")),
conditionalPanel(condition= "input.modtab=='DC # 25'", tableOutput("modelingdevice1DC25")),
conditionalPanel(condition= "input.modtab=='DC # 40'", tableOutput("modelingdevice1DC40")),
conditionalPanel(condition= "input.modtab=='DC # 125'", tableOutput("modelingdevice1DC125")),
conditionalPanel(condition= "input.modtab=='DC # 150'", tableOutput("modelingdevice1DC150")),# plotlyOutput("plotcv1"),br(), tableOutput("device1cv")),
conditionalPanel(condition="input.modtab=='TLP'",tableOutput("modelingdevice1TLP")),# plotlyOutput("plottlp1"),br(), tableOutput("device1tlp")),
conditionalPanel(condition="input.modtab=='VFTLP'",tableOutput("modelingdevice1VFTLP"))#, plotlyOutput("plotvftlp1"),br(), tableOutput("device1vftlp"))
),
tabItem("IPL",
fluidRow(box(title = "Model Inputs", width = 8,
fileInput("iplfile", "choose the IPL file", accept = c(".xlsx"), multiple = TRUE),
column(3, uiOutput("modeltype")),
column(3,uiOutput("modeldevtype")),
column(3,uiOutput("modelpath")),
column(3, uiOutput("wrapperfile")),
column(3,uiOutput("zapcon")),
column(3,uiOutput("polarity")),
column(3,uiOutput("sectiontype")),
column(3,uiOutput("designfile")),
column(3, uiOutput("esd_event")),
column(3, uiOutput("esd_exit")),
column(3, uiOutput("modelnodeorder")),
column(3, uiOutput("terminalbias")),
column(3,uiOutput("design")),
column(3,uiOutput("modtemp")),
column(3,uiOutput("ylogaxis")))),
box(title = "Model Parameters in IPL", width = 20, tableOutput("IPLTable"),
uiOutput("newvalue1"),
uiOutput("newvalue2"),
uiOutput("newvalue3"),
uiOutput("newvalue4"))
,fluidRow(box(width = 6, height = 60,actionButton("SpecPlot", label="Spectre Plot", width = 100),
# bsModal("netl", strong("Netlist File", style="color:#0000ff; font-size:120%"),
# "gennet", size = "large", uiOutput("modelnetlist")),
actionButton("HspiPlot", label="Hspice Plot", width = 100),
actionButton("gennet", label="Generate netlist"),
actionButton("ChangeValues", label="Change Values"),
actionButton("save", label = "Save"),
actionButton("Mergesim", label="Merge Simulation Plots"))),
uiOutput("newvalues"),
#conditionalPanel(condition = "input$specplot", withSpinner(plotlyOutput("plotspe"), type = 1, hide.ui = FALSE)),
tags$head(
tags$style(
HTML(".shiny-notification {
height: 100px;
width: 500px;
position:fixed;
top: calc(50% - 50px);;
left: calc(50% - 400px);;
}
"
)
)
),
#box(title = "Simulation", status = "primary", plotlyOutput("plotspe", height = 250)),
fluidRow(column(width=6,
fluidRow(plotlyOutput("plotspe",width = "100%", height = "400px", inline = FALSE))),
column(width=6,
fluidRow(plotlyOutput("plothspi",width = "100%", height = "400px", inline = FALSE)))),
fluidRow(column(width=6,fluidRow(plotlyOutput("plotspechspi",width = "100%", height = "400px", inline = FALSE)))),
# splitLayout(style = "height:400px;", cellWidths = c("800", "800"),
# plotlyOutput("plotspe"), plotlyOutput("plothspi"))
# ,
plotlyOutput("plottlpalongspectre")
),
tabItem("netlist", fluidPage(uiOutput("netlistfile"))),
tabItem("mylog", fluidPage(uiOutput("logfile"))),
tabItem("QA", " QA tab content")# actionButton("ChangeValues", label="Change Values"
)
)
)
**run.scs file:** (File that I'm calling in modelnetlist function to read and display it in the modal)
Simmulator lang=spectre
global 0
paropt options redefinedparams= ignore
parameters vnw=0 vnd=0
parameters area_1=5.5e-12
I would like to edit in the modal popup, but I'm only to print with my code. I tried textInput, textOutput inside modalDialog but it doesn't help. Any suggestions?
In modalDialog function you can use almost any UI elements (see ... parameter)
modelnetlist <- function(failed = FALSE){
netlistdata <- paste(readLines('run.scs'),collapse="\n")
modalDialog(
title = "Netlist File",
textAreaInput("theScript", value=netlistdata),
easyClose = FALSE,
footer = tagList(
modalButton("Close"),
actionButton("save", "Save")
)
)
}
and to get new script in the save button listener use input$theScript
observeEvent(input$save, {
# do whatever you want with input$theScript
if(isTruthy(input$theScript))
writeLines(input$theScript, "run.scs")
})
Note: the path where you save file must be writeable.

Change default CSS styling of `shinydashboardPlus::descriptionBlock()`

I find shinydashboardPlus::descriptionBlock() quite nice but I am a bit frustrated not being able to change its styling within R. How can we achieve that?
header is necessarly bold,
text is necessarly in UPPERCASE,
Using HTML() in number put the icon to the next line.
Show case:
library(shiny)
library(shinydashboard)
shinyApp(
ui = dashboardPage(
dashboardHeader(),
dashboardSidebar(),
dashboardBody(
box(
solidHeader = FALSE,
title = "Status summary",
background = NULL,
width = 4,
status = "danger",
footer = fluidRow(
column(
width = 6,
descriptionBlock(
number = "17%",
numberColor = "green",
numberIcon = "caret-up",
header = "not bold please",
text = "set me in lowercase please",
rightBorder = TRUE,
marginBottom = FALSE
)
),
column(
width = 6,
descriptionBlock(
number = HTML("<h4>icon?</h4>"),
numberColor = "red",
numberIcon = "skull-crossbones",
header = "using html put",
text = "icon to next line",
rightBorder = FALSE,
marginBottom = FALSE
)
)
)
)
),
title = "Description Blocks"
),
server = function(input, output) { }
)
To solve this problems you need to insert css statements that equally specific as the css code supplied by the package.
To sole the bold header insert .description-block>.description-header { font-weight: 500; }
to remove the always Uppercase insert .description-block>.description-text { text-transform: none; }
With the Icon problem. The problem is that you are using a <h4> tag. And this is by default a block element which moves the next object to a new line. Here you can either use a different tag such as <span> or set the display attribute to inline-block. In the example below I used the later solution
All together it would look like this
library(shiny)
library(shinydashboard)
shinyApp(
ui = dashboardPage(
dashboardHeader(),
dashboardSidebar(),
dashboardBody(
tags$head(
tags$style(
HTML("
.description-block>.description-text {
text-transform: none;
}
.description-block>.description-header {
font-weight: 500;
}
.description-percentage>h4 {
display: inline-block;
}
")
)
),
box(
solidHeader = FALSE,
title = "Status summary",
background = NULL,
width = 4,
status = "danger",
footer = fluidRow(
column(
width = 6,
descriptionBlock(
number = "17%",
numberColor = "green",
numberIcon = "caret-up",
header = "not bold please",
text = "set me in lowercase please",
rightBorder = TRUE,
marginBottom = FALSE
)
),
column(
width = 6,
descriptionBlock(
number = HTML("<h4>icon?</h4>"),
numberColor = "red",
numberIcon = "skull-crossbones",
header = "using html put",
text = "icon to next line",
rightBorder = FALSE,
marginBottom = FALSE
)
)
)
)
),
title = "Description Blocks"
),
server = function(input, output) { }
)

Unable to hide/show a fluid page in RShiny application

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)

Number not displaying inside circle created with CSS on shinydashboard

I've created a circle with CSS that should contain a number in the middle, with the help of this SO answer
# Packages
library(shinydashboard)
library(tidyverse)
library(readxl)
library(scales)
theme_set(theme_light())
header <- dashboardHeader(
title = "Test App",
titleWidth = 215
)
sidebar <- dashboardSidebar(
sidebarMenu(
menuItem("Test Tab", tabName = "test_tab",
icon = icon("paper-plane"), startExpanded = TRUE)
)
)
body <- dashboardBody(
includeCSS("www/style.css"),
tabItems(
tabItem(tabName = "test_tab",
fluidRow(
column(width = 4,
h2("Column X"),
valueBoxOutput("first_value", width = NULL),
box(flexdashboard::gaugeOutput("second_value", width = "90%", height = "100px"),
title = "Second Value", status = "primary", solidHeader = TRUE,
collapsible = FALSE, width = NULL
)
),
column(width = 8,
h2("Column Y"),
box(tags$div(id="insidediv", textOutput("test_div")),
title = "#3", status = "primary", solidHeader = TRUE,
collapsible = FALSE, width = 4
),
box(
title = "#4", status = "primary", solidHeader = TRUE,
collapsible = FALSE, width = 4
)
)
),
fluidRow(
h2("Row A"),
column(width = 12,
box(title = "Third Value", status = "primary", solidHeader = TRUE,
width = 2.4),
box("Fourth Value", status = "primary", solidHeader = TRUE,
width = 2.4),
box("Fifth Value", status = "primary", solidHeader = TRUE,
width = 2.4),
box("Sixth Value", status = "primary", solidHeader = TRUE,
width = 2.4),
box("Seventh Value", status = "primary", solidHeader = TRUE,
width = 2.4)
)
)
)
)
)
# Put them together into a dashboardPage
ui <- dashboardPage(skin = "blue", header = header,
sidebar = sidebar,
body = body)
server <- function(input, output) {
output$first_value <- renderValueBox({
valueBox(
comma_format()(100000),
subtitle = "First Value",
icon = icon("list"), color = "purple"
)
})
output$second_value = flexdashboard::renderGauge({
flexdashboard::gauge(0.12 * 100,
symbol = '%',
min = 0,
max = 100)
})
output$test_div <- renderText({
"141"
})
}
shinyApp(ui, server)
Unfortunately, the number doesn't appear inside the circle, but outside it... Does anyone know what the problem may be???
The linked SO answer seems to have it right, but under different circumstances... maybe since I'm putting it inside a box(), its different?
If you are not familiar with it:
The CSS # Selector is for giving ONE specific HTML Element a specific look. Shiny gives textOutput an ID which is test_div in your example. You also have to use that ID in your CSS to style the element.
#test_div {
padding-top: 30px;
padding-bottom: 30px;
text-align: center;
font-weight: bold;
font-size: 24px;
}
I had to play around with the padding, which defines the space around the elements content. Instead of pixels you can also use % (padding: 5%)
https://www.w3schools.com/css/css_padding.asp
Learning the basics of CSS is quite easy and will improve your abitilies to make look shiny a lot :-).

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