How to center the image in a brilliant application?

I play with the application:

http://shiny.rstudio.com/gallery/plot-plus-three-columns.html

I insert picture in the top line, pasting this under the heading

list(img(src="NFL_Header.jpg", width = 400, align = "center")), 

But left justified, align doesn't seem to do anything. How to specify center alignment for an image?

+5
source share
2 answers

From Yihui itself:

The align <img /> attribute is not what you need. Another thing ( http://www.w3schools.com/tags/att_img_align.asp ). You can use style="display: block; margin-left: auto; margin-right: auto;" to center the image. Or div(img(...), style="text-align: center;") .

+9
source

Using HTML , you can put the entire img tag in the center tag:

 HTML('<center><img src="NFL_Header.jpg"></center>') 

enter image description here

In case of link break:

ui.R

  library(shiny) library(ggplot2) dataset <- diamonds shinyUI(fluidPage( title = "Diamonds Explorer", HTML('<center><img src="NFL_Header.jpg" width="400"></center>'), plotOutput('plot'), hr(), fluidRow( column(3, h4("Diamonds Explorer"), sliderInput('sampleSize', 'Sample Size', min=1, max=nrow(dataset), value=min(1000, nrow(dataset)), step=500, round=0), br(), checkboxInput('jitter', 'Jitter'), checkboxInput('smooth', 'Smooth') ), column(4, offset = 1, selectInput('x', 'X', names(dataset)), selectInput('y', 'Y', names(dataset), names(dataset)[[2]]), selectInput('color', 'Color', c('None', names(dataset))) ), column(4, selectInput('facet_row', 'Facet Row', c(None='.', names(diamonds[sapply(diamonds, is.factor)]))), selectInput('facet_col', 'Facet Column', c(None='.', names(diamonds[sapply(diamonds, is.factor)]))) ) ) )) 

server.R

 library(shiny) library(ggplot2) shinyServer(function(input, output) { dataset <- reactive({ diamonds[sample(nrow(diamonds), input$sampleSize),] }) output$plot <- renderPlot({ p <- ggplot(dataset(), aes_string(x=input$x, y=input$y)) + geom_point() if (input$color != 'None') p <- p + aes_string(color=input$color) facets <- paste(input$facet_row, '~', input$facet_col) if (facets != '. ~ .') p <- p + facet_grid(facets) if (input$jitter) p <- p + geom_jitter() if (input$smooth) p <- p + geom_smooth() print(p) }) }) 
+2
source

Source: https://habr.com/ru/post/1240113/


All Articles