Collapsible box in Shiny App - css

library(shiny)
# Define UI for application that draws a histogram
ui <- fluidPage(
includeCSS(path = "AdminLTE.css"), #added
includeCSS(path = "shinydashboard.css"), #added
# Application title
titlePanel("Old Faithful Geyser Data"),
# Sidebar with a slider input for number of bins
sidebarLayout(
sidebarPanel(
sliderInput("bins",
"Number of bins:",
min = 1,
max = 50,
value = 30)
),
# Show a plot of the generated distribution
mainPanel(
box(plotOutput("distPlot"), solidHeader = T, collapsible = T, title = "collapsible box not collapsing", status = "primary")
)
)
)
# Define server logic required to draw a histogram
server <- function(input, output) {
output$distPlot <- renderPlot({
# generate bins based on input$bins from ui.R
x <- faithful[, 2]
bins <- seq(min(x), max(x), length.out = input$bins + 1)
# draw the histogram with the specified number of bins
hist(x, breaks = bins, col = 'darkgray', border = 'white')
})
}
# Run the application
shinyApp(ui = ui, server = server)
This result is
In the above image the collpasible box is not getting collapsed when clicked on mininize button.
I have added the addtional AdminLTE.css and shinydashboard.css file in working directory, but still problem persists.

To use a collapsible box within shiny only. We need to add the required javascript. Just after adding css we add this file as well.
includeCSS(path = "AdminLTE.css"), #added
includeCSS(path = "shinydashboard.css"), #added
#add this file and collapsible nature should work.
includeScript(path = "app.js"), #

If you don't have a restriction to use shinydashboard, just create a dash board page without the header and the sidebar. It will enable all the features of shinydashboard and it will looks like a basic shiny app. In the code below the box collapse/uncollapse when you click on the minimize/maximize button.
library(shiny)
library(shinydashboard)
ui <- dashboardPage(
dashboardHeader(disable = TRUE),
dashboardSidebar(disable = TRUE),
dashboardBody(
# Application title
titlePanel("Old Faithful Geyser Data"),
# Sidebar with a slider input for number of bins
sidebarLayout(
sidebarPanel(
sliderInput("bins", "Number of bins:", min = 1, max = 50, value = 30)
),
# Show a plot of the generated distribution
mainPanel(
box(plotOutput("distPlot"), solidHeader = T, collapsible = T,
title = "collapsible box not collapsing", status = "primary")
)
)
)
)
# Define server logic required to draw a histogram
server <- function(input, output) {
output$distPlot <- renderPlot({
# generate bins based on input$bins from ui.R
x <- faithful[, 2]
bins <- seq(min(x), max(x), length.out = input$bins + 1)
# draw the histogram with the specified number of bins
hist(x, breaks = bins, col = 'darkgray', border = 'white')
})
}
# Run the application
shinyApp(ui = ui, server = server)

Related

Change font color in shiny dashboard titlePanel

I'm trying to make the title of my dashboard in red, but when I try to pass the style argument in my titlePanel, I get an error that the argument is unused. What am I doing wrong?
library(shiny)
# Define UI for application that draws a histogram
ui <- fluidPage(
# Application title
titlePanel("Old Faithful Geyser Data", style = "color: #FFFFFF"),
# Sidebar with a slider input for number of bins
sidebarLayout(
sidebarPanel(
sliderInput("bins",
"Number of bins:",
min = 1,
max = 50,
value = 30)
),
# Show a plot of the generated distribution
mainPanel(
plotOutput("distPlot")
)
)
)
# Define server logic required to draw a histogram
server <- function(input, output) {
output$distPlot <- renderPlot({
# generate bins based on input$bins from ui.R
x <- faithful[, 2]
bins <- seq(min(x), max(x), length.out = input$bins + 1)
# draw the histogram with the specified number of bins
hist(x, breaks = bins, col = 'darkgray', border = 'white')
})
}
# Run the application
shinyApp(ui = ui, server = server)
Here's the error:
Error in titlePanel("Old Faithful Geyser Data", style = "color: #FFFFFF") :
unused argument (style = "color: #FFFFFF")
Wrap it in a div as
titlePanel(div("Old Faithful Geyser Data", style = "color: #FF0000"))

Create a small window to describe the meaning of filters in Shiny

Friends, I would like to add a brief explanation about each filter used. Then, whenever you click on the filter name, a small window appears with a brief informative text about the meaning of that filter. I left an image attached to illustrate.
So, for example, if I click on "Number of bins" the description of the meaning of this filter appears. Obviously, if you click outside that info window, the info text will exit.
How can I do this in shiny?
library(shiny)
ui <- fluidPage(
titlePanel("Old Faithful Geyser Data"),
sidebarLayout(
sidebarPanel(
sliderInput("bins",
"Number of bins:",
min = 1,
max = 50,
value = 30)
),
sidebarLayout(
sidebarPanel(
sliderInput("bins",
"Number of bins:",
min = 1,
max = 20,
value = 30),
),
mainPanel(
plotOutput("distPlot")
)
)
))
server <- function(input, output) {
output$distPlot <- renderPlot({
# generate bins based on input$bins from ui.R
x <- faithful[, 2]
bins <- seq(min(x), max(x), length.out = input$bins + 1)
# draw the histogram with the specified number of bins
hist(x, breaks = bins, col = 'darkgray', border = 'white')
})
}
# Run the application
shinyApp(ui = ui, server = server)
Thank you very much!
You could use shinyBS for that - either bsTooltip, popify, or tipify. Example:
Edit:
Switched to popify.
library(shinyBS)
library(shiny)
ui <- fluidPage(
titlePanel("Old Faithful Geyser Data"),
sidebarLayout(
sidebarPanel(
popify(
sliderInput("bins",
"Number of bins:",
min = 1,
max = 20,
value = 30),
title = "Number of bins",
content = paste0("Number of bins refers to.....")
)
),
mainPanel(
plotOutput("distPlot")
)
)
)
server <- function(input, output) {
output$distPlot <- renderPlot({
# generate bins based on input$bins from ui.R
x <- faithful[, 2]
bins <- seq(min(x), max(x), length.out = input$bins + 1)
# draw the histogram with the specified number of bins
hist(x, breaks = bins, col = 'darkgray', border = 'white')
})
}
# Run the application
shinyApp(ui = ui, server = server)

Movable panel in Shiny

In the following code,
is it possible to put bins in movable panel like the color change panel.
The follwoing image shows one panel is movable but the other is not movable.
library(shiny)
# Define UI for application that draws a histogram
ui <- fluidPage(
shiny::tags$head(
shinythemes::themeSelector()
),#taghead
# Application title
titlePanel("Old Faithful Geyser Data"),
# Sidebar with a slider input for number of bins
sidebarLayout(
sidebarPanel(
sliderInput("bins",
"Number of bins:",
min = 1,
max = 50,
value = 30)
),
# Show a plot of the generated distribution
mainPanel(
plotOutput("distPlot")
)
)
)
# Define server logic required to draw a histogram
server <- function(input, output) {
output$distPlot <- renderPlot({
# generate bins based on input$bins from ui.R
x <- faithful[, 2]
bins <- seq(min(x), max(x), length.out = input$bins + 1)
# draw the histogram with the specified number of bins
hist(x, breaks = bins, col = 'darkgray', border = 'white')
})
}
# Run the application
shinyApp(ui = ui, server = server)
How to make movable panel?
Please let me know.
**Answer: The following code makes a draggable panel**
library(shiny)
# Define UI for application that draws a histogram
ui <- fluidPage(
shiny::tags$head(
shinythemes::themeSelector()
),#taghead
# Application title
titlePanel("Old Faithful Geyser Data"),
# Sidebar with a slider input for number of bins
# Show a plot of the generated distribution
mainPanel(
absolutePanel(
sliderInput("bins",
"Number of bins:",
min = 1,
max = 50,
value = 30),
draggable = T
),
plotOutput("distPlot")
)
)
# Define server logic required to draw a histogram
server <- function(input, output) {
output$distPlot <- renderPlot({
# generate bins based on input$bins from ui.R
x <- faithful[, 2]
bins <- seq(min(x), max(x), length.out = input$bins + 1)
# draw the histogram with the specified number of bins
hist(x, breaks = bins, col = 'darkgray', border = 'white')
})
}
# Run the application
shinyApp(ui = ui, server = server)
Movable panels can be achieved with absolutePanel.

italic font in titlePanel within the shiny app

Is there a way to get italic words in my shiny titlePanel?
I tried
library(shiny)
# Define UI for application that draws a histogram
ui <- shinyUI(fluidPage(
# Application title
titlePanel("Old <em>Faithful Geyser</em> Data"),
# Sidebar with a slider input for number of bins
sidebarLayout(
sidebarPanel(
sliderInput("bins",
"Number of bins:",
min = 1,
max = 50,
value = 30)
),
# Show a plot of the generated distribution
mainPanel(
plotOutput("distPlot")
)
)
))
# Define server logic required to draw a histogram
server <- shinyServer(function(input, output) {
output$distPlot <- renderPlot({
# generate bins based on input$bins from ui.R
x <- faithful[, 2]
bins <- seq(min(x), max(x), length.out = input$bins + 1)
# draw the histogram with the specified number of bins
hist(x, breaks = bins, col = 'darkgray', border = 'white')
})
})
# Run the application
shinyApp(ui = ui, server = server)
and this print the title as Old <em>Faithful Geyser</em> Data. The em does not get interpreted. Am I doing something wrong or isn't there a way to get italic font in the title?
hello try this it should work
titlePanel( div(HTML("Old <em>Faithful Geyser</em> Data")))

Is it possible to use both absolute panel and sliderInput in same ui.R (shiny)?

This is my ui.R. This is an example provided in Shiny tutorial. I just edited it.
library(shiny)
library(markdown)
# Define UI for application that draws a histogram
shinyUI(fluidPage(
# Application title
titlePanel("Hello Shiny!"),
# Sidebar with a slider input for the number of bins
sidebarLayout(
sidebarPanel(
sliderInput("bins",
"Number of bins:",
min = 1,
max = 50,
value = 30)
),
# Show a plot of the generated distribution
mainPanel(
plotOutput("distPlot"),
absolutePanel(
bottom = 0, left=420, width = 800,
draggable = TRUE,
wellPanel(
em("This panel can be moved")
)
)
))
))
and my server. R
library(shiny)
# Define server logic required to draw a histogram
shinyServer(function(input, output) {
# Expression that generates a histogram. The expression is
# wrapped in a call to renderPlot to indicate that:
#
# 1) It is "reactive" and therefore should be automatically
# re-executed when inputs change
# 2) Its output type is a plot
output$distPlot <- renderPlot({
x <- faithful[, 2] # Old Faithful Geyser data
bins <- seq(min(x), max(x), length.out = input$bins + 1)
# draw the histogram with the specified number of bins
hist(x, breaks = bins, col = 'darkgray', border = 'white')
})
})**
In this case, sliderInput is not working. If i remove absolute panel, sliderInput is ok. What may be the problem? Many thanks
The absolutePanel uses the jqueryui javascript library. It has its own slider. This results in a conflict with sliderInput which uses jslider library. You can see this as follows:
library(shiny)
runApp(
list(ui = fluidPage(
titlePanel("Hello Shiny!"),
sidebarLayout(
sidebarPanel(
sliderInput("bins",
"Number of bins:",
min = 1,
max = 50,
value = 30)
),
mainPanel(
plotOutput("distPlot")
, tags$head(tags$script(src = "shared/jqueryui/1.10.3/jquery-ui.min.js"))
)
)
),
server = function(input, output) {
output$distPlot <- renderPlot({
x <- faithful[, 2] # Old Faithful Geyser data
bins <- seq(min(x), max(x), length.out = input$bins + 1)
hist(x, breaks = bins, col = 'darkgray', border = 'white')
})
}
)
)
EDIT: This has been fixed in the latest dev version of shiny. The slider component has been removed from the jqueryui inc. https://github.com/rstudio/shiny/commit/7e12a281f51e047336ba2c501fcac43af5253225

Resources