I have a 99% working minimal example here. The only thing I would like to change is to have the rank number next to the letter rather than on the line above it.
library(shiny)
library(sortable)
addDiv <- function(x) {lapply(x,function(x){tags$div(x)})}
ui <- fluidPage(
tags$head(
tags$style(HTML('
#rank_list_basic > div {cursor: move; #fallback
cursor: grab; cursor: pointer;}
#rank_list_basic {list-style-type: none; counter-reset: css-counter 0;}
#rank_list_basic > div {counter-increment: css-counter 1;}
#rank_list_basic > div:before {content: counter(css-counter) ". ";}
')
)
),
fluidRow(
rank_list(
text = "Drag the items in any desired order",
labels = addDiv(c("A","B","C","D","E")),
input_id = "output",
css_id = "rank_list_basic"
),
verbatimTextOutput("results_basic")
)
)
server <- function(input, output) {
output$results_basic <- renderPrint({
input$output
})
}
shinyApp(ui, server)
You need to simply put your labels in a list instead of using addDiv:
library(shiny)
library(sortable)
addDiv <- function(x) {lapply(x,function(x){tags$div(x)})}
ui <- fluidPage(
tags$head(
tags$style(HTML('
#rank_list_basic > div {cursor: move; #fallback
cursor: grab; cursor: pointer;}
#rank_list_basic {list-style-type: none; counter-reset: css-counter 0;}
#rank_list_basic > div {counter-increment: css-counter 1;}
#rank_list_basic > div:before {content: counter(css-counter) ". ";}
')
)
),
fluidRow(
rank_list(
text = "Drag the items in any desired order",
labels = list("A","B","C","D","E"),
input_id = "output",
css_id = "rank_list_basic"
),
verbatimTextOutput("results_basic")
)
)
server <- function(input, output) {
output$results_basic <- renderPrint({
input$output
})
}
shinyApp(ui, server)
Related
I have shiny application with tabBox as shown below:
library(shiny)
library(shinydashboard)
body <- dashboardBody(
fluidRow(tags$style(".nav-tabs {
background-color: #006747;
}
.nav-tabs-custom .nav-tabs li.active:hover a, .nav-tabs-custom .nav-tabs li.active a {
background-color: transparent;
border-color: transparent;
}
.nav-tabs-custom .nav-tabs li.active {
border-top-color: #990d5e;
}
.content-wrapper {
background-color: #FFF;
}"),
tabBox(
title = "First tabBox",
# The id lets us use input$tabset1 on the server to find the current tab
id = "tabset1", height = "250px",
tabPanel("Tab1", "First tab content"),
tabPanel("Tab2", "Tab content 2")
)
))
shinyApp(
ui = dashboardPage(
dashboardHeader(title = "tabBoxes"),
dashboardSidebar(),
body
),
server = function(input, output) {
}
)
I would like to hide/remove the grey border lines of the tabBox on all sides as indicated by arrows in the picture.
Could someone help which CSS class has to be used to make this change?
You can set box-shadow: none; for class .nav-tabs-custom:
library(shiny)
library(shinydashboard)
body <- dashboardBody(
fluidRow(tags$style(".nav-tabs {
background-color: #006747;
}
.nav-tabs-custom .nav-tabs li.active:hover a, .nav-tabs-custom .nav-tabs li.active a {
background-color: transparent;
border-color: transparent;
}
.nav-tabs-custom .nav-tabs li.active {
border-top-color: #990d5e;
}
.content-wrapper {
background-color: #FFF;
}
.nav-tabs-custom {
box-shadow: none;
}
"),
tabBox(
title = "First tabBox",
# The id lets us use input$tabset1 on the server to find the current tab
id = "tabset1", height = "250px",
tabPanel("Tab1", "First tab content"),
tabPanel("Tab2", "Tab content 2")
)
))
shinyApp(
ui = dashboardPage(
dashboardHeader(title = "tabBoxes"),
dashboardSidebar(),
body
),
server = function(input, output) {}
)
I am using R's bsplus package to build a carousel of images. I want to move the chevrons next to the bullets.
I am aware of this SO sol'n regarding how to reposition the prev/next chevrons.
I can get close (see the 'right' chevron) but when I position it where I want it (see the 'left' chevron) it's no longer clickable.
Why is this?
How can I position the chevrons next to the bullets and maintain their functionality?
R Script
library("shiny")
library("bsplus")
ui <- fluidPage(
includeCSS("/home/law/whatbank_home/tests/bullet.css"),
# Application title
titlePanel("Carousel Demo"),
uiOutput("carousel")
)
server <- shinyServer(function(input, output) {
output$carousel <- renderUI({
bs_carousel(id = "images", use_indicators = TRUE) %>%
bs_append(
content = bs_carousel_image(src = "https://placehold.it/900x500/3c8dbc/ffffff&text=Merry")
) %>%
bs_append(
content = bs_carousel_image(src = "https://placehold.it/900x500/3c8dbc/ffffff&text=Christmas")
) %>%
bs_append(
content = bs_carousel_image(src = "https://placehold.it/900x500/3c8dbc/ffffff&text=To")
) %>%
bs_append(
content = bs_carousel_image(src = "https://placehold.it/900x500/3c8dbc/ffffff&text=All")
)
})
})
# Run the application
shinyApp(ui = ui, server = server)
css
.carousel-control.left,
.carousel-control.right {
background: transparent;
}
.carousel-indicators .active {
background-color: #FCB700;
margin-bottom: 70px;
}
.carousel-indicators li {
background-color: #D8D8D8;
border: 1px solid #000;
margin-bottom: 70px;
}
.carousel-control.left .glyphicon {
left: 180px;
margin-left: 180px;
top: 183px;
margin-top: 183px;
}
.carousel-control.right .glyphicon {
right: 180px;
margin-right: 180px;
top: 160px;
margin-top: 160px;
}
You should try
.carousel-control {
width: 2%
}
In the example below, I use 2%.
library(shiny)
library(shinydashboardPlus) ### carousel() is from this package
library(DT)
jscode <-"
$(document).ready(function(){
$('#mycarousel').carousel( { interval: false } );
});"
shinyApp(
ui = dashboardPage(
header = dashboardHeader(),
sidebar = dashboardSidebar(),
body = dashboardBody(
tags$head(
tags$style(HTML("
#mycarousel {
width:900px;
height:600px;
}
.carousel-control{
color:#FF0000;
width: 2%;
}
"))
),
tags$head(tags$script(HTML(jscode))),
carousel(
id = "mycarousel",
carouselItem(
DTOutput("show_iris_dt")
),
carouselItem(
caption = "An image file",
tags$img(src = "YBS.png")
),
carouselItem(
caption = "Item 3",
tags$img(src = "http://placehold.it/900x500/39CCCC/ffffff&text=Happy+New+Year")
)
)
),
title = "Carousel Demo"
),
server = function(input, output) {
output$show_iris_dt <- renderDT({
datatable(iris)
})
}
)
Using navbarPage I would like to have some tabPanels to be right-aligned while the rest of tabPanels and navbarMenus to be left-aligned:
So, instead of this
library(shiny)
ui = tagList(
navbarPage(
title = "My app",
navbarMenu("Left1",
tabPanel("Subleft11"),
tabPanel("Subleft12")),
tabPanel("Left2"),
tabPanel("Left3"),
tabPanel("Right1"),
tabPanel("Right2")
)
)
server <- function(input, output, session) {}
shinyApp(ui, server)
I would like to get something like this:
Solution from GyD works fine for tabsetPanel but I was not able to adapt it to navbarPage. I tried to add
tags$head(
tags$style(HTML(
".navbar ul li:nth-child(4) { float: right; }
.navbar ul li:nth-child(5) { float: right; }"
))),
but without desired effect.
You could do that with some css.
This would be an easy example which aligns the 4th and 5th list elements inside the class navbar-nav a float: right;.
By including right: 150px; to the 4th child, you keep the tabs in correct order.
App.R
library(shiny)
library(shinythemes)
ui = tagList(
tags$head(tags$style(HTML("
.navbar-nav {
float: none !important;
}
.navbar-nav > li:nth-child(4) {
float: right;
right: 150px;
}
.navbar-nav > li:nth-child(5) {
float: right;
}
"))),
navbarPage(
title = "My app",
theme = shinytheme("cerulean"),
navbarMenu("Left1",
tabPanel("Subleft11"),
tabPanel("Subleft12")),
tabPanel("Left2"),
tabPanel("Left3"),
tabPanel("Right1"),
tabPanel("Right2")
)
)
server <- function(input, output, session) {}
shinyApp(ui, server)
Maybe something along these lines:
tags$head(
tags$style(HTML(
"
.navbar-header { width: 10% }
.navbar-nav { width: 90% }
.navbar-nav>li:nth-child(4) { float: right; }
.navbar-nav>li:nth-child(5) { float: right; }"
)))
Current status of the boxes :
I am unable to improve the following things :
Have the text in a row by itself(The Select the modules... one)
The box and text are not aligned on the same line.
The checkboxes on the top line are slightly truncated.(the remaining is encircled below)
The labels(a to j) need to be in white bold text.
This is what I have tried so far :
ui.R :
library(shiny)
controls <- list(tags$div(align = 'left',
class = 'multicol',
checkboxGroupInput(inputId = 'modules',
label = "Step 1 : Select the modules to be executed",
choices = c(process_names),
selected = "",
inline = FALSE)))
shinyUI(fluidPage(
tags$style(type='text/css', "label {font-size: 22px; } # controls the text of check-boxes
.form-group {margin-top: 5px; margin-bottom: 5px;}
.nav-tabs {font-family:'arial';font-size:20px}
#sidebar {background-color: #5C97BF;}
#mainbar {background-color: #5C97BF;}
body { background-color: #002B55;}
input[type=checkbox] {transform: scale(2);}
.multicol {height: 200px; -webkit-column-count: 4;
-moz-column-count: 4; /* Firefox */
column-count: 4; -moz-column-fill: auto;-column-fill: auto;} # increases the size of checkboxes
div.checkbox {margin-top: 10px;color:'#FFFFFF';font-weight: bold; }
.btn {display:block;height: 60px;width: 40px;border-radius: 50%;} # for actionButton
"),
sidebarLayout(
position = "left",
sidebarPanel(controls),
mainPanel()
)
))
server.R
shinyServer(
function(input, output){
}
)
Here's fixed code for your app:
library(shiny)
process_names <- letters[1:13]
controls <- tags$div(
tags$label("Step 1 : Select the modules to be executed"),
tags$div(align = 'left',
class = 'multicol',
checkboxGroupInput(inputId = 'modules',
label = NULL,
choices = c(process_names),
selected = "",
inline = FALSE)))
ui<-(fluidPage(
tags$style(type='text/css', "label {font-size: 22px; }
.form-group {margin-top: 5px; margin-bottom: 5px;}
.nav-tabs {font-family:'arial';font-size:20px}
#sidebar {background-color: #5C97BF;}
#mainbar {background-color: #5C97BF;}
body { background-color: #002B55;}
input[type=checkbox] {transform: scale(2);margin-top:10px;}
.multicol {height: 200px; -webkit-column-count: 4;
-moz-column-count: 4; /* Firefox */
column-count: 4; -moz-column-fill: auto;-column-fill: auto;}
.checkbox {margin-top:-5px;}
.btn {display:block;height: 60px;width: 40px;border-radius: 50%;}
#modules .checkbox label span {font-weight:bold;}
label {color:#fff;}
"),
sidebarLayout(
position = "left",
sidebarPanel(controls),
mainPanel()
)
))
server<-function(input,output){}
shinyApp(ui,server)
This takes care of all your issues. Note that one big problem you had (that took me a long time to debug!) is that you cannot use # as comments inside CSS. That breaks your CSS. You can only use /* comment here */ as comments in CSS.
To have the label on a single line, set label = NULL and add a p("text") before the checkBox() to have it on a single line.
To have the text in 'white', add a style="color:#FFFFFF" to the list(tags$div().
I'm still trying to figure out why the boxes are slightly truncated.
I am developing a R Shiny Application that use the shinyWidgets library. I use 2 times the radioGroupButtons widget. I would like to make it green the first time, and red the second time, using CSS. (In reality I want to make more customisation).
Here is a basic code, applying CSS to every buttons. How can I apply 2 CSS classes?
Thank you very very much for your help !
library("shinyWidgets")
library(shiny)
# Useless server
server <- function(input, output) {
output$distPlot <- renderPlot({
hist(rnorm(input$button1), col = 'skyblue', border = 'white')
})
}
# Ui
ui <- fluidPage(
sidebarLayout(
sidebarPanel(
# A CSS for every .btn button
tags$style(HTML("
.btn {
color: #2ecc71;
border: 2px #2ecc71 solid;
}
.btn:hover {
color: #fff;
background-color: #2ecc71;
}
.btn-default.active, .btn-default:active, .open > .dropdown-toggle.btn-default {
color: #fff;
background-color: #2ecc71;
border-color: #2ecc71;
}
")),
# first radio button, it is green!
radioGroupButtons("button1", label = "It's green !!", choices=c("choice1"=50, "Choice2"=100, "Choice3"=150), selected=100),
# second radio button, I wish it is red!
radioGroupButtons("button2", label = "I wish I was red :( ...", choices=c("choice1"=1, "Choice2"=2), selected=1)
),
mainPanel(plotOutput("distPlot"))
)
)
shinyApp(ui = ui, server = server)
So you want to add some specific classes to your radioGroupButtons. Well, ShinyWidgets doesn't let you, so why not create your own radioButtons widget function.
(Well, this function will be almost entirely copied from radioGroupButtons)
Hint: Type radioGroupButton into the R Console to view the source code.
And lets tweak that function, such that it accepts a class argument, which will be applied to the html element. Then, you can easily access the different radioGroupButton-classes with your CSS.
Working code below:
library("shinyWidgets")
library(shiny)
# Defining the new Widget.
customRadioGroupButtons <- function (inputId, label = NULL, choices, selected = NULL, status = "default", size = "normal", direction = "horizontal", justified = FALSE, individual = FALSE, checkIcon = list(), class=NULL) {
choices <- shinyWidgets:::choicesWithNames(choices)
if (!is.null(selected) && length(selected) > 1)
stop("selected must be length 1")
if (is.null(selected))
selected <- choices[1]
size <- match.arg(arg = size, choices = c("xs", "sm", "normal",
"lg"))
direction <- match.arg(arg = direction, choices = c("horizontal",
"vertical"))
status <- match.arg(arg = status, choices = c("default",
"primary", "success", "info", "warning", "danger"))
divClass <- if (individual)
""
else "btn-group"
if (!individual & direction == "vertical") {
divClass <- paste0(divClass, "-vertical")
}
if (justified) {
divClass <- paste(divClass, "btn-group-justified")
}
if (size != "normal") {
divClass <- paste0(divClass, " btn-group-", size)
}
# Below here, the paste call is the only difference to the original function.
radioGroupButtonsTag <- tagList(tags$div(id = inputId, class = paste("radioGroupButtons", class),
if (!is.null(label))
tags$label(class = "control-label", `for` = inputId, label),
if (!is.null(label))
br(), style = "margin-top: 3px; margin-bottom: 3px; ", style = if (justified) "width: 100%;",
tags$div(class = divClass, role = "group",
`aria-label` = "...", `data-toggle` = "buttons",
class = "btn-group-container-sw", shinyWidgets:::generateRGB(inputId, choices, selected, status, size, checkIcon))))
shinyWidgets:::attachShinyWidgetsDep(radioGroupButtonsTag)
}
# Useless server
server <- function(input, output) {
output$distPlot <- renderPlot({
hist(rnorm(input$button1), col = 'skyblue', border = 'white')
})
}
# Ui
ui <- fluidPage(
sidebarLayout(
sidebarPanel(
# Note: Consider making a function if you use this more often.
tags$style(HTML("
.radioGroupButtons.green .btn {
color: #2ecc71;
border: 2px #2ecc71 solid;
}
.radioGroupButtons.green .btn:hover {
color: #fff;
background-color: #2ecc71;
}
.radioGroupButtons.green .btn-default.active, .radioGroupButtons.green .btn-default:active, .radioGroupButtons.green .open > .dropdown-toggle.btn-default {
color: #fff;
background-color: #2ecc71;
border-color: #2ecc71;
}
.radioGroupButtons.red .btn {
color: #EE102B;
border: 2px #EE102B solid;
}
.radioGroupButtons.red .btn:hover {
color: #fff;
background-color: #EE102B;
}
.radioGroupButtons.red .btn-default.active, .radioGroupButtons.green .btn-default:active, .radioGroupButtons.green .open > .dropdown-toggle.btn-default {
color: #fff;
background-color: #EE102B;
border-color: #EE102B;
}
")),
# first radio button, it is green!
customRadioGroupButtons("button1", class="green", label = "It's green !!", choices=c("choice1"=50, "Choice2"=100, "Choice3"=150), selected=100),
# second radio button, I wish it is red!
customRadioGroupButtons("button2", class="red", label = "I wish I was red :( ...", choices=c("choice1"=1, "Choice2"=2), selected=1)
),
mainPanel(plotOutput("distPlot"))
)
)
shinyApp(ui = ui, server = server)
You can add a Bootstrap status then overwrite the class, for example if you add status = "danger", buttons will have class btn-danger :
I can remove the limitation to valid Bootstrap status in the function, it could be useful for such styling (fill an issue here so i remenber).
library("shinyWidgets")
library("shiny")
# Useless server
server <- function(input, output) {
output$distPlot <- renderPlot({
hist(rnorm(input$button1), col = 'skyblue', border = 'white')
})
}
# Ui
ui <- fluidPage(
sidebarLayout(
sidebarPanel(
# A CSS for every .btn button
tags$style(HTML("
.btn-success.btn {
color: #2ecc71;
background-color: #fff;
border: 2px #2ecc71 solid;
}
.btn-success.btn:hover {
color: #fff;
background-color: #2ecc71;
}
.btn-success.active {
color: #fff;
background-color: #2ecc71;
border-color: #2ecc71;
}
.btn-danger.btn {
color: #EE102B;
background-color: #fff;
border: 2px #EE102B solid;
}
.btn-danger.btn:hover {
color: #fff;
background-color: #EE102B;
}
.btn-danger.active {
color: #fff;
background-color: #EE102B;
border-color: #EE102B;
}
")),
# first radio button, it is green!
radioGroupButtons("button1", label = "It's green !!", status = "success", choices=c("choice1"=50, "Choice2"=100, "Choice3"=150), selected=100),
# second radio button, I wish it is red!
radioGroupButtons("button2", label = "I wish I was red :( ...", status = "danger", choices=c("choice1"=1, "Choice2"=2), selected=1)
),
mainPanel(plotOutput("distPlot"))
)
)
shinyApp(ui = ui, server = server)