I'm building a Shiny app with this UI. Here is nhl-logo.png
ui <- fluidPage(
titlePanel(tagList(
img(src = "nhl-logo.png", height = 60, width = 60),
"PLAY-BY-PLAY"),
windowTitle = "NHL Play-by-Play"),
div(style = "position:absolute;right:2em;",
actionButton('load_inputs', 'Load inputs'),
actionButton('save_inputs', 'Save inputs')
),
hr(),
fluidRow(...)
Unfortunately, the style is not what I want since it puts those actionButtons on a lower level than the title (NHL LOGO PLAY-BY-PLAY)
How do I change the style so that my actionButtons appear on the same horizontal level as the titlePanel?
You can add the title in a span which includes the buttons. The difference between a span and a div is that the span is inline (a div is a block).
ui <- fluidPage(
titlePanel(tagList(
img(src = "nhl-logo.png", height = 60, width = 60),
span("PLAY-BY-PLAY",
span(actionButton('load_inputs', 'Load inputs'),
actionButton('save_inputs', 'Save inputs'),
style = "position:absolute;right:2em;")
)
),
windowTitle = "NHL Play-by-Play"
),
hr(),
fluidRow()
)
server <- function(input, output, session) {
}
shinyApp(ui, server)
Related
I'm having trouble with the formats of conditional panels affecting other conditional panels. Below is reproducible code, and at the bottom are images better explaining the issue. In the fuller App this code derives from, the problem is more obvious and makes it look sloppy (in the fuller App, there are multiple screens the user clicks through as the user scrolls to the right along the shaded bar (Well Panel) at the top just underneath the tab label, and the misalignment gets more pronounced as the user scrolls to the right).
The problem is: as the user scrolls right through the Glide Controls / Well Panels to make selections, the Well Panels (at the top with radio buttons) begin to misalign with the table and/or plots that appear beneath. The misalignment gets more pronounced as the user scrolls right. This misalignment isn't as apparent in this reproducible example, but is more pronounced in the fuller App this derives from where there are multiple "screens" or Well Panels at the top for the user to scroll through and where there are data tables and/or plots presented underneath in the main panel.
For sake of simplicity all server code is eliminated in this example (no plots, no tables), as the issue still presents without the server code.
If I comment-out other conditional panels (marked "###" in the reproducible code) the misalignment goes away. So how can I make the conditional panels independent of one another, as a way of eliminating this misalignment? I'm open to any other suggestions for eliminating this misalignment.
The basic structure of the App is the user makes "big choices" along the sidebar panel, and makes more "refined choices" only the top bar underneath the tab label using Glide Controls/Well Panels etc. for a carousel affect.
Reproducible code:
library(shiny)
library(shinyglide)
library(shinyjs)
library(shinyWidgets)
ui <-
fluidPage(
useShinyjs(),
tags$style(".glide-controls { position: absolute; top: 8px; right: 14px; width: 160px; }"),
titlePanel("Hello"),
sidebarLayout(
sidebarPanel(selectInput("selectData", h5(strong("Select data to view:")),choices = list("Stratification","DnL balances"),selected = "Stratification")),
mainPanel(
tabsetPanel(
tabPanel("Private data", value = 1,
div(style = "margin-top:10px"),
conditionalPanel(condition = "input.selectData == 'Stratification'",
fluidRow(
column(12,
glide(
custom_controls = div(class = "glide-controls", glideControls()),
screen(
wellPanel(
radioButtons(
inputId = 'groupStrats',
label = NULL,
choiceNames = c('Calendar period','MOB'),
choiceValues = c('Period','MOB'),
selected = 'Period',
inline = TRUE),
style = "padding-top: 12px; padding-bottom: 0px;")
),
screen(
wellPanel(
radioButtons(
inputId = 'stratsView',
label = NULL,
choices = list("Table view" = 1,"Plot view" = 2),
selected = 1,
inline = TRUE),
style = "padding-top: 12px; padding-bottom: 0px;")
)
)
)
),
### Deleting next line resolves the well panel issue ###
conditionalPanel(condition = "input.stratsView == 2",fluidRow(column(12, plotOutput("stratPlot"))))
),
### Deleting the following conditional panel also resolves the well panel issue ###
conditionalPanel(condition = "input.selectData == 'DnL balances'",
fluidRow(
column(12,
glide(
custom_controls = div(class = "glide-controls", glideControls()),
screen(
wellPanel(
radioButtons(
inputId = 'groupBal',
label = NULL,
choiceNames = c('Calendar period','MOB'),
choiceValues = c('Period','MOB'),
selected = 'Period',
inline = TRUE),
style = "padding-top: 12px; padding-bottom: 0px;")
)
)
)
)
), # closes conditional panel
### Deleting the following conditional panel (or either checkbox... or selectize...) also resolves the well panel issue ###
conditionalPanel(condition = "input.selectData == 'Level 1 data'",
panel(
checkboxGroupInput(
inputId = "vars",
label = "Filter by (default view is all data):",
choices = c("Period", "MOB"),
selected = c("Period", "MOB"),
inline = TRUE),
selectizeGroupUI(
id = "my-filters",
params = list(Period = list(inputId = "Period", title = "Period:"),
MOB = list(inputId = "MOB", title = "MOB:"))
), # closes above selectize...
status = "primary"
)
) # closes conditional panel
), id = "tabselected"
)
)
)
)
server <- function(input, output, session) {}
shinyApp(ui, server)
Actually this is the same issue as here.
The conditionalPanels are visible for a very short time when first invoking the app.
This causes a vertical scrollbar to appear and leads to the misalignment.
Use style = "display: none;" to render the conditionalPanels hidden on startup (where needed) and please leave a thumbs up or other feedback here.
library(shiny)
library(shinyjs)
library(shinyglide)
library(shinyWidgets)
ui <-
fluidPage(
useShinyjs(),
tags$style(".glide-controls { position: absolute; top: 8px; right: 14px; width: 160px; }"),
titlePanel("Hello"),
sidebarLayout(
sidebarPanel(selectInput("selectData", h5(strong("Select data to view:")),choices = list("Stratification","DnL balances"),selected = "Stratification")),
mainPanel(
tabsetPanel(
tabPanel("Private data", value = 1,
div(style = "margin-top:10px"),
conditionalPanel(condition = "input.selectData == 'Stratification'",
fluidRow(
column(12,
glide(
custom_controls = div(class = "glide-controls", glideControls()),
screen(
wellPanel(
radioButtons(
inputId = 'groupStrats',
label = NULL,
choiceNames = c('Calendar period','MOB'),
choiceValues = c('Period','MOB'),
selected = 'Period',
inline = TRUE),
style = "padding-top: 12px; padding-bottom: 0px;")
),
screen(
wellPanel(
radioButtons(
inputId = 'stratsView',
label = NULL,
choices = list("Table view" = 1,"Plot view" = 2),
selected = 1,
inline = TRUE),
style = "padding-top: 12px; padding-bottom: 0px;")
)
)
)
),
### Deleting next line resolves the well panel issue ###
conditionalPanel(condition = "input.stratsView == 2", style = "display: none;", fluidRow(column(12, plotOutput("stratPlot"))))
),
### Deleting the following conditional panel also resolves the well panel issue ###
conditionalPanel(condition = "input.selectData == 'DnL balances'", style = "display: none;",
fluidRow(
column(12,
glide(
custom_controls = div(class = "glide-controls", glideControls()),
screen(
wellPanel(
radioButtons(
inputId = 'groupBal',
label = NULL,
choiceNames = c('Calendar period','MOB'),
choiceValues = c('Period','MOB'),
selected = 'Period',
inline = TRUE),
style = "padding-top: 12px; padding-bottom: 0px;")
)
)
)
)
), # closes conditional panel
### Deleting the following conditional panel (or either checkbox... or selectize...) also resolves the well panel issue ###
conditionalPanel(condition = "input.selectData == 'Level 1 data'", style = "display: none;",
panel(
checkboxGroupInput(
inputId = "vars",
label = "Filter by (default view is all data):",
choices = c("Period", "MOB"),
selected = c("Period", "MOB"),
inline = TRUE),
selectizeGroupUI(
id = "my-filters",
params = list(Period = list(inputId = "Period", title = "Period:"),
MOB = list(inputId = "MOB", title = "MOB:"))
), # closes above selectize...
status = "primary"
)
) # closes conditional panel
), id = "tabselected"
)
)
)
)
server <- function(input, output, session) {}
shinyApp(ui, server)
I have a shiny app, and I want to add a small line break in between 2 objects--is it possible to specify that you want br() to be half it's regular size? I know if I wanted it to be double the size, I'd do br(), br(), but I don't know how to make it smaller.
Instead of br() you can add a margin to the bottom of the element of any size.
library(shiny)
ui <- fluidPage(
p("Line 1"),
br(),
p("Line 2", style = "margin-bottom: 0px;"),
p("Line 3", style = "margin-bottom: -10px;"),
p("Line 4")
)
server <- function(input, output) {
}
shinyApp(ui = ui, server = server)
I am trying to fix my width on my R Shiny map. Also, I am not succeeding in making the panel faded. The width and faded panel I want to replicate is here at this link:
https://shiny.rstudio.com/gallery/superzip-example.html
I am using their style css file, this link: https://github.com/rstudio/shiny-examples/blob/master/063-superzip-example/styles.css
I have written my code:
library(shiny)
library(tidyverse)
library(leaflet.extras)
library(leaflet)
library(RColorBrewer)
library(scales)
library(lattice)
library(dplyr)
fake_data <- read.csv("https://raw.githubusercontent.com/gabrielburcea/stackoverflow_fake_data/master/gather_divided.csv")
# Define UI for application that draws a histogram
ui <- fluidPage(
navbarPage("Covid-19 Symptom Tracker", id = "nav",
tabPanel("Interactive map",
div(class = "outer",
tags$head(
tags$link(rel = "stylesheet", type = "text/css", href = "style.css")
),
leafletOutput("map", width = "100%", height = "96vh"), #height = "99vh"
#Floating panel
absolutePanel(id = "controls", class = "panel panel-default", fixed = TRUE,
draggable = TRUE, top = 60, left = "auto", right = 20, bottom = "auto",
width = 330, height = "auto",
h4("SARS-Covid-19 symptoms"),
selectInput("symptom", "Select symptom", c("Chills",
"Cough", "Diarrhoea",
"Fatigue",
"Headache",
"Loss of smell and taste",
"Muscle ache",
"Nasal congestion",
"Nausea and vomiting",
"Shortness of breath",
"Sore throat",
"Sputum",
"Temperature")
),
tags$div(id="cite",
'Data provided by Your.md'
)
)))
)
)
server <- function(input, output) {
filtered_data <- reactive({
fake_data %>%
dplyr::filter(Symptom %in% input$symptom)
})
output$map <- renderLeaflet({
leaflet() %>%
addTiles(urlTemplate = "//{s}.tiles.mapbox.com/v3/jcheng.map-5ebohr46/{z}/{x}/{y}.png",
attribution = 'Maps by Mapbox') %>%
addMarkers(data = filtered_data(), clusterOptions = markerClusterOptions())
})
}
# Run the application
shinyApp(ui = ui, server = server)
And the css style I am using (just the same as theirs) is here:
https://github.com/gabrielburcea/stackoverflow_fake_data/blob/master/style.css
The panel I have is this which is obviously different than the one in the link I provided:
I get the following output:
when I run your code. I like the floating dialog box which fades. There is some white space along the title, and some more when I zoom out completely. It looks fine to me. Also, I saved the CSS file via Notepad. I don't think that should make any difference if you saved it via RStudio.
I am working on a Shiny dashboard and using valueBoxes to display current KPI's. What I am noticing though, is depending on how long some of the text is, it elongates the box to fit the text which then screws up the look.
How do I make it so the text is always only on it's 1 line (i.e. change the font to be the width of the box) no matter what the screen size is?
Also, if you have any HTML or CSS pointers to make the information in a better layout, let me know.
I have to display:
value
description of what the value represents
estimation of future
value
In my actual dashboard:
I have the box background color changed
rounded out the edges
Have the value font color change based on thresholds
Code:
ui <- dashboardPage(
dashboardHeader(title = "Dynamic boxes"),
dashboardSidebar(),
dashboardBody(
fluidRow(
valueBoxOutput("vbox", width = 2),
valueBoxOutput("vbox2", width = 2),
valueBoxOutput("vbox3", width = 2),
valueBoxOutput("vbox4", width = 2),
valueBoxOutput("vbox5", width = 2),
valueBoxOutput("vbox6", width = 2)
)
)
)
server <- function(input, output) {
output$vbox <- renderValueBox({
valueBox(
"55%",
HTML(paste("test_value that is super long like this",br(),"Estimated: 98%")),
icon = icon("credit-card")
)
})
output$vbox2 <- renderValueBox({
valueBox(
"70%",
HTML(paste("this one is just as long, maybe even longer",br(),"Estimated: 100%")),
icon = icon("credit-card")
)
})
output$vbox3 <- renderValueBox({
valueBox(
"80%",
HTML(paste("this one is short",br(),"Estimated: 50%")),
icon = icon("credit-card")
)
})
output$vbox4 <- renderValueBox({
valueBox(
"100%",
HTML(paste("medium length like here",br(),"Estimated: 95%")),
icon = icon("credit-card")
)
})
output$vbox5 <- renderValueBox({
valueBox(
"90%",
HTML(paste("test_value that is super long like this",br(),"Estimated: 80%")),
icon = icon("credit-card")
)
})
output$vbox6 <- renderValueBox({
valueBox(
"40%",
HTML(paste("test_value that is super long like this",br(),"Estimated: 70%")),
icon = icon("credit-card")
)
})
}
shinyApp(ui, server)
}
I used shiny-dashboard package and the header needs to have a title, a text and a logo.
Title should be on the left side, text should be in the middle/center of the header and logo should be on the right side. Dashboard sidebar has also two filters (select inputs).The text in the middle is showing the user selections and therefore the length of the text is different based on various selections. I don't have a css background and not sure how to position the variable length text at the center of the header. Another problem is that when I minimize my screen, the text and logo stack on top of each other and don't stay in one line as shown below:
To simplify the code, I just used a simple text and I didn't show my server code here but "long text with variable length dependant on user selections" is basically a uiOutput and will be changed based on selections.
shinyApp(
ui = dashboardPage(
dashboardHeader(
title = HTML(paste0("Dashboard example")) , titleWidth = 455,
tags$li(class="dropdown",
tags$table(style="80%;align:center;border-collapse:seperate;border-spacing:20px;",
tags$tr(
tags$td(h3("long text with variable length dependant on user selections")),
tags$td(
a(href='link',
img(src = 'http://www.clipartbest.com/cliparts/nTX/8nj/nTX8njyEc.jpeg',
title= "image title", height = "50px"),
style = "display:block;position:absolute,width:50px; padding-top:10px; padding-bottom:10px;padding-right:10px;"),
class="dropdown"))))),
dashboardSidebar(),
dashboardBody(tags$head(
tags$style(HTML("
.my_class {
font-weight: bold;
color:white;
}"))
))),
server = function(input, output) { }
)
Minimizing the screen breaks the header as below
Using the code provided below, I get this.
Try something like this:
library(shiny)
library(shinydashboard)
shinyApp(
ui = dashboardPage(
dashboardHeader(
title = "Dashboard example",
titleWidth = 455,
tags$li(
class = "dropdown",
fluidRow(
column(
width = 4,
offset = 4,
align = "center",
span("long text with variable length dependant on user selections")
),
column(
width = 4,
align = "right",
img(src = 'http://www.clipartbest.com/cliparts/nTX/8nj/nTX8njyEc.jpeg')
)
)
)
),
dashboardSidebar(width = 455),
dashboardBody(
tags$style(
".main-header .navbar-custom-menu {
width: calc(100% - 50px);
}
.main-header .navbar-nav,
.main-header .dropdown {
width: 100%;
}
.main-header img {
height: 50px
}"
)
)
),
server = function(input, output) {}
)