italic font in titlePanel within the shiny app - r

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")))

Related

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.

Shiny not responsive to multiple tabsetpanels

I'm trying to include multiple tabsetPanel in the mainPanel of a Shiny app. When I launch the app, it's not showing anything as if the app is trying to figure out the UI element without getting into the server elements at all.
Anyone knows why this is the case?
Below is a minimal example based on the Shiny app template in RStudio.
ui.R
library(shiny)
# Define UI for application that draws a histogram
shinyUI(fluidPage(
# Sidebar with a slider input for number of bins
sidebarLayout(
sidebarPanel(
sliderInput("bins",
"Number of bins:",
min = 1,
max = 50,
value = 30)
),
# Multiple tabset panels
mainPanel(
h2("tabsetpanel1"),
tabsetPanel(id = "pan1",
type = "tabs",
tabPanel("tab1", plotOutput("distPlot"))),
h2("tabsetpanel2"),
tabsetPanel(id = "pan2",
type = "tabs",
tabPanel("tab2", plotOutput("distPlot")))
)
)
))
server.R
library(shiny)
# Define server logic required to draw a histogram
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')
})
})
Your outputs have to be unique you cant have multiple "distPlot", Change to something like this:
data <- reactive({
# 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')
})
output$distPlot1 <- renderPlot({
data()
})
output$distPlot2 <- renderPlot({
data()
})
Then in your ui
plotOutput("distPlot1")
plotOutput("distPlot2")

Collapsible box in Shiny App

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)

R shiny hide mainPanel object during computation time

I have a shiny app with a longer computation depending on the input. I am wondering if it is possible to display a text in the main panel at the same time when the computation is done (and not before).
Let's make an easy example. I simulated the longer computation with Sys.sleep():
# Define UI for application that draws a histogram
ui <- shinyUI(fluidPage(
# 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(
h3('This is an example'),
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')
Sys.sleep(5)
})
})
# Run the application
shinyApp(ui = ui, server = server)
The goal would be, to show the text 'This is an example' at the same time the computation is done and not before.
I think I have to make the text somehow reactive, but so far I haven't found a solution for this. Maybe a conditionalPanel could do it, but how can I bring the computation time in the condition? Any ideas?
Would this be what you search for? Your text variable as a reactive after observing the event of distPlot
library(shiny)
# Define UI for application that draws a histogram
ui <- shinyUI(fluidPage(
# 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(
textOutput('text1'),
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')
Sys.sleep(2)
})
observeEvent(plotOutput("distPlot"), {
output$text1 <- renderText({ paste("Number of bins:", input$bins)})
})
})
# Run the application
shinyApp(ui = ui, server = server)

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