How to place an image in an R Shiny title
One way would be to follow the directions in this post: How can I insert an image into the navbar on a shiny navbarPage() (The SO hounds would attack this as a duplicate).
Create a folder called 'www' in your working directory and place 'picture.jpg' inside as so:
| shinyApp/
| ui.R
| server.R
| www/
| picture.png
Include your picture in titlePanel with a div:
ui.r
library(shiny)
# Define UI for random distribution application
shinyUI(fluidPage(#theme="bootstrap.css",
# Application title
titlePanel(title=div(img(src="picture.jpg"), "My Title")),
sidebarLayout(
sidebarPanel(
)
)
)
)
Shiny titlepanel: how to put title and image at same height?
So I figured it out myself while trying to solve the same problem in a wellPanel.
The bad guy is the offset
argument in column()
. If I remove it, the image and title are horizontally aligned.
To put the image on the right, I just have to make the left column very wide:
titlePanel(
fluidRow(
column(9, "Fenologische modellen"),
column(3, img(height = 105, width = 300, src = "logo_pcfruit.jpg"))
)
),
Align image in title panel in shiny
You could try:
ui <- fluidPage (
titlePanel(title=div("mytitle",
img(src="mypicture.jpeg",
style="position:absolute;right:15px;z-index:1000000;")))
)
The large z-index
ensures the image is in front of everything.
R Shiny - How to position an image from top
Earlier I used "ShinyUI" and now changed to "dashboardPage" which itself solved the issue and the image got automatically adjusted and aligned.
Below are the arguments I used.
title = tags$a(href = 'https://google.com',
tags$img(src = 'logo.png', height= 50,width= 50, align = "left"),
'Title')
header = dashboardHeader(title = title, titleWidth = 400)
ui = dashboardPage(header, sidebar, body, tags$head(tags$link(rel = "stylesheet", type = "text/css", href = "custom1.css")))
Thanks to Abhinav...
watch this video for more details
Add image and title in the same row of the header section of a shiny dashboard
Perhaps your are looking for this. You can play with padding and margins to get appropriate spacing.
mytitle <- paste0("Life, Death and Statins")
dbHeader <- dashboardHeaderPlus(
titleWidth = "0px",
tags$li(a(href = "https://www.mit.edu/", # 'http://https://www.uow.edu.au/',
div(style = "margin-left:-15px;margin-bottom:-44px;margin-top:-15px;padding: 0px 1190px 0px 0px ; width: 290px;",
img(src = 'YBS.png', height = "55px",width="232px")),
div(style="display: inline; padding: 0px 90px 0px 750px ; font-size: 40px ; width: 300px;",HTML(mytitle, "<br>"))
),
class = "dropdown")
)
Related Topics
Converting Date Column in Data Frame
Efficiently Counting Non-Na Elements in Data.Table
How to Round a Date to the Quarter Start/End
Determining Minimum Values in a Vector in R
How to Draw a Contour Plot When Data Are Not on a Regular Grid
Update() Inside a Function Only Searches the Global Environment
Na Matches Na, But Is Not Equal to Na. Why
R - Min, Max and Mean of Off-Diagonal Elements in a Matrix
Font Awesome in R, Loaded But Not Found by Waffle
How to Add "Author" Metadata to a PDF Created from R
Ggplot2: Cannot Color Area Between Intersecting Lines Using Geom_Ribbon
How to Add Main Title and Manipulating Axis Labels in Ggplot2 in Rstudio
How to Use a Non-Ascii Symbol (E.G. £) in an R Package Function