r - 在 Shiny 的fluidRow中水平居中图像

标签 r user-interface shiny

是否可以在 Shiny 的 ui fluidPage 中将三个图像居中放在一行中,并将每个图像的宽度固定为 300 像素?获取:

enter image description here

我的一个想法是使用 splitLayout 并以某种方式插入图像作为窗口宽度的函数,但我不确定如何实现这一点。我知道您可以使用 splitLayout 将图像设置为窗口的百分比,但是我特别希望中间图像为 300 像素。

fluidPage(fluidRow(
    splitLayout(cellWidths = c("34%", 300, "34%"), cellArgs = list(style = "padding: 0px"), style = "border: 0px; padding: 0px;",
       div(img(src="image1", height=300, width=300, align="right"),
       div(img(src="image2", height=300, width=300, align="center"),
       div(img(src="image3", height=300, width=300, align="left")), ...

所以问题是我得到的图像偏离中心:

enter image description here

但是当我将中间单元格设置为 33% 时,图像之间的差距太大了。

splitLayout(cellWidths = c("34%", "33%", "34%"), cellArgs = list(style = "padding: 0px"), style = "border: 0px; padding: 0px;",
div(img(src="image1", height=300, width=300, align="right"),
div(img(src="image2", height=300, width=300, align="center"),
div(img(src="image3", height=300, width=300, align="left"))

enter image description here

所以我所追求的是 cellWidths = c((windowWidth-300)/2, 300, (windowWidth-300)/2) 但我不确定如何提取 windowWidth。

最佳答案

我设法使用 column 函数修复它,我只是错过了 align="center" 参数以及样式中宽度参数的删除。例如:

library(shiny)

server = function(input, output, session) {}

ui <- fluidPage(fluidRow(
         column(12, align="center",
                div(style="display: inline-block;",img(src="image1", height=300, width=300)),
                div(style="display: inline-block;",img(src="image2", height=300, width=300)),
                div(style="display: inline-block;",img(src="image3", height=300, width=300))))
)


shinyApp(ui = ui, server = server)

关于r - 在 Shiny 的fluidRow中水平居中图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47551311/

相关文章:

r - ggplot2 标签 : Combination of Greek symbol and exponential term,

r - 如何将 ggplot 对象向量传递给 grid.arrange 函数?

c# - 以图形方式模板化 .NET winforms 应用程序

python - 即使我使用 destroy/pack_forget,Tkinter Widget 也不会消失

R Shiny - 使用 DataTable 移动列名

r - 用于多个 renderPlot 函数的过滤数据框

R:如何将 xts 对象转换为数值矩阵?

r - 如何在R中按顺序重新编号组ID?

linux - Linux 中的 GUI 开发

javascript - 如何选择 Shiny 的DT数据表中的最大单元格数