I created a dashboard using shinyDashboard and I have a map with leaflet. The box element used in shinyDashboard creates a fixed height of 400px for the map.
I would like the map to be 90vh so that it covers most of the screen, and so I wrote this on the UI file:
tabItem(tabName = "widgets",
fluidPage(
fluidRow(
tags$head(tags$style(type = "text/css",'
#geomap {
height: 90vh;
}
')),
box(title = "Geographical distribution",
leafletOutput("geomap")
)
)
)
)
Now, when I inspect the page, I can see that the property was passed onto the #geomap id, but it is overridden for some reason
!
Also, here is the node
.
I have overridden classes before successfully, so I don't understand how an ID can't be overridden. Any ideas?
Thank you!
EDIT: Here's an example code:
library(shiny)
library(shinydashboard)
library(leaflet)
server <- function(input, output, session) {
output$geomap <- renderLeaflet({
m <- leaflet(data) %>%
addProviderTiles("CartoDB.Positron")
})
}
ui <- dashboardPage(skin = "black",
dashboardHeader(title = "Test"),
dashboardSidebar(
sidebarMenu(
menuItem("Map distribution", tabName = "widgets", icon = icon("th"))
)
),
dashboardBody(
tabItems(
tabItem(tabName = "widgets",
fluidPage(
fluidRow(
tags$head(tags$style(HTML('
.col-sm-6 {
width: 100%;
}
'))),
box(title = "Geographical distribution",
leafletOutput("geomap")
)
)
)
)
)
)
)
shinyApp(ui, server)
Related
I have this shiny app I am making. My goal is to have a fluid row that has an image and some inputs
# Test Version with google logo
library(shinydashboard)
library(shiny)
ui <- dashboardPage(
dashboardHeader(title = "Dashbaord"),
dashboardSidebar(
sidebarMenuOutput("menu")
),
dashboardBody(
fluidRow(
box(
title = "Image Goes Here",
img(src='https://cdn.vox-cdn.com/thumbor/ULiGDiA4_u4SaK-xexvmJVYUNY0=/0x0:640x427/1400x1050/filters:focal(0x0:640x427):format(jpeg)/cdn.vox-cdn.com/assets/3218223/google.jpg',
align = "center",
width = "100%",
style="height: 50px")), #I'm trying to change the size here but it doesn't work
box(align = "center",
title = "Select Inputs",status = "warning", solidHeader = F,
selectInput("dropdown1", "Select Drilldown:", c(50,100,200))
)
)
)
)
server <- function(input, output) {
}
shinyApp(ui, server)
Technically this code works, but I don't like how the box with the image changes based off the monitor/view. I would like for both boxes to be the same height and remain uniformed. I posted some screen shots below.
Full Screen
Half Screen
Desire Output (row is the same height no matter what).
Edit:
box_height = "20em"
plot_height = "16em"
ui <- dashboardPage(
dashboardHeader(title = "Box alignmnent test"),
dashboardSidebar(),
dashboardBody(
# Put boxes in a row
fluidRow(
box(
title = "Image Goes Here",
img(src='https://cdn.vox-cdn.com/thumbor/ULiGDiA4_u4SaK-xexvmJVYUNY0=/0x0:640x427/1400x1050/filters:focal(0x0:640x427):format(jpeg)/cdn.vox-cdn.com/assets/3218223/google.jpg',
align = "center",
width = "100%"),
height = box_height),
box(plotOutput("speed_distbn",height = plot_height), height = box_height)
)
)
)
server <- function(input, output) {
}
shinyApp(ui, server)
Boxes stay the same height but the image overlaps the box
How about this
library(shinydashboard)
library(shiny)
my_height = "30em"
ui <- dashboardPage(
dashboardHeader(title = "Box alignmnent test"),
dashboardSidebar(),
dashboardBody(
# Put boxes in a row
fluidRow(
box(
title = "Image Goes Here",
img(src='https://cdn.vox-cdn.com/thumbor/ULiGDiA4_u4SaK-xexvmJVYUNY0=/0x0:640x427/1400x1050/filters:focal(0x0:640x427):format(jpeg)/cdn.vox-cdn.com/assets/3218223/google.jpg',
align = "center", style = paste0("width: 100%; height: ", my_height, ";"))
),
box(title = "Plot", plotOutput("speed_distbn", height = my_height))
)
)
)
server <- function(input, output) {
output$speed_distbn <- renderPlot(plot(1))
}
shinyApp(ui, server)
In your first case, if you want to use other random tags on the right side. In order to have the right the same height as left, we can use spsComps::heightMatcher. We can use this function to dynamically match the height of the right side to the left side.
library(shinydashboard)
library(shiny)
my_height = "30em"
ui <- dashboardPage(
dashboardHeader(title = "Box alignmnent test"),
dashboardSidebar(),
dashboardBody(
# Put boxes in a row
fluidRow(
box(
title = "Image Goes Here",
id= "box_l",
img(src='https://cdn.vox-cdn.com/thumbor/ULiGDiA4_u4SaK-xexvmJVYUNY0=/0x0:640x427/1400x1050/filters:focal(0x0:640x427):format(jpeg)/cdn.vox-cdn.com/assets/3218223/google.jpg',
align = "center", style = paste0("width: 100%; height: ", my_height, ";"))
),
box(
title = "Select inputs",
id= "box_r",
selectInput("dropdown1", "Select Drilldown:", c(50,100,200))
),
spsComps::heightMatcher("box_r", "box_l")
)
)
)
server <- function(input, output) {
}
shinyApp(ui, server)
In your case, the height on left is fixed, but heightMatcher can do it even with dynamically changed height. try click on spsComps shiny demo and go to the Misc tab and see the dynamic heightMatcher example.
I am trying to insert an local image inside a tabitem in shiny app, but some challenges and load it on the page. Could someone help to solve this issue? My code attempt is:
CODE
if (interactive()) {
library(shiny)
library(shinydashboard)
ui <- dashboardPage(skin = "blue",
dashboardHeader(),
dashboardSidebar(
sidebarMenu(
id = "tabs",
menuItem("Dogs", icon = icon("dog"), tabName = "Dogs"),
menuItem("Data", icon = icon("table"), tabName = "Data")
)),
dashboardBody(
mainPanel(
tabItems(
tabItem(tabName = "Dogs", class='active', role="figure",
tags$img(src="dogdogs.png")
)))),
tags$head(
tags$style(HTML(" .main-sidebar {background-color: blue;}"))
)
)
server <- function(input, output) { }
shinyApp(ui, server)
}
Thanks in advance
I have the shiny dashboard below and I need to change the color of the header that includes the title permanently. Now when I hover over it returns to previous color.
library(DT)
ui <- dashboardPage(
dashboardHeader(title = "Dynamic sidebar"),
dashboardSidebar(
width=400
),
dashboardBody(
tags$head(tags$style(HTML('
/* logo */
.skin-blue .main-header .logo {
background-color: #E7FF6E;
}')))
)
)
server <- function(input, output) {
}
shinyApp(ui, server)
You can create a custom theme to use with {shinydashboard} with the {fresh} package, more documentation here : https://dreamrs.github.io/fresh/articles/vars-shinydashboard.html
Here an example to modify header background color:
library(fresh)
# Create the theme
mytheme <- create_theme(
adminlte_color(
light_blue = "#E7FF6E"
)
)
library(shiny)
library(shinydashboard)
ui <- dashboardPage(
header = dashboardHeader(title = "My dashboard"),
sidebar = dashboardSidebar(
sidebarMenu(
menuItem("Dashboard", tabName = "dashboard", icon = icon("dashboard")),
menuItem("Settings", tabName = "settings", icon = icon("sliders"))
)
),
body = dashboardBody(
use_theme(mytheme) # <-- use the theme
)
)
server <- function(input, output, session) {
}
shinyApp(ui, server)
I am trying to render shinydashboard after login page but shinydashboard skin color is not showing.
my code is as follow:
ui.r
library(shinydashboard)
library(shiny)
uiOutput("page")
Login.R
library(shinydashboard)
ui1Output <- function(id, label = "ui1") {
shinyUI(fluidPage(
mainPanel(
textInput("username","Username",placeholder ="UserName"),
passwordInput("password","Password", placeholder ="Password"),
actionButton("login", "Login")
)))
}
dashbaordpage.R
library(shinydashboard)
dashpageOutput <- dashboardPage(
dashboardHeader(title = "Basic dashboard"),
dashboardSidebar(
sidebarMenu(
menuItem("Dashboard", tabName = "dashboard", icon = icon("dashboard")),
menuItem("Widgets", tabName = "widgets", icon = icon("th"))
)
),
dashboardBody(
tabItems(
# First tab content
tabItem(tabName = "dashboard",h2("Dashbaord")),
# Second tab content
tabItem(tabName = "widgets",
h2("Widgets tab content")
)
)
)
global.R
source('login.R') #login page
source('dashboardPage.R')#dashbaordpage
server.R
library(shiny)
library(shinydashboard)
shinyServer(function(input, output,session) {
output$page <- renderUI({
ui1Output('ui1Output')
})
observeEvent(input$login,
{
if(True)
{
output$page <- renderUI(dashpageOutput)
}
else
{
Logged<-F
showModal(modalDialog(
title = "Error",
"Enter Correct Username and password"
))
}
})
})
Details: when I going dashboard is showing but not with default skin color or any other skin color. I have tried skin='red' like wise option.
Image for reference how actually showing after login.
Please help me.
Thanks in advance.
I have a very basic infoBox like this, and want to adjust the height as the current height is just way too much for what I am incorporating.
Any idea how I can do it? I tried what was suggested here: r shinydashboard - change height of valueBox. But, that is not having any change.
sidebar <- dashboardSidebar(
sidebarMenu(id = 'sidebarmenu',
menuItem('About', tabName = 'about'))
)
about <- tabItem('about', fluidPage(
fluidRow(
infoBoxOutput('age')
)
)
)
body <- dashboardBody(
tabItems(
about
)
)
ui <- dashboardPage(
dashboardHeader(
title = 'My App'
),
sidebar = sidebar,
body = body
)
server <- function(input, output) {
output$age <- renderInfoBox({
infoBox('Age: ', 50, icon = icon('list'), width = 6)
})
}
shinyApp(ui = ui, server = server)
You need to apply some CSS rules.
body <- dashboardBody(
tags$head(tags$style(HTML('.info-box {min-height: 45px;} .info-box-icon {height: 45px; line-height: 45px;} .info-box-content {padding-top: 0px; padding-bottom: 0px;}'))),
tabItems(
about
)
)