html - 在 Shiny 中垂直对齐图像
问题描述
我正在尝试在 Shiny 的 tabPanel 的第二列中垂直对齐图像。我已经设法将它水平对齐(使用 align="center"),但如果不插入几个 br() 就无法垂直对齐它。我高度怀疑必须有一个更优雅的解决方案来做到这一点。下面是我的代码示例(不包括 br())。任何建议,将不胜感激。在此先感谢您的帮助!
mainPanel(
tabsetPanel(type = "tabs",
tabPanel("Plot",
column(width = 6,
plotOutput("plot")),
column(width = 6, align="center",
img(src = "image.jpg", height=140, width=140),
)),
tabPanel("Summary", verbatimTextOutput("summary")),
tabPanel("Table", tableOutput("table"))
)
解决方案
一个不太好的解决方案可以大大减少 br() 拥塞:
library(shiny)
library(purrr)
n_br <- 17
ui <- fluidPage(
mainPanel(
tabsetPanel(type = "tabs",
tabPanel("Plot",
column(width = 6,
plotOutput("plot")),
column(width = 6, align="center",
map(1:n_br, ~br()), #add n number of br()
img(src = "image.jpg", height=140, width=140),
)),
tabPanel("Summary", verbatimTextOutput("summary")),
tabPanel("Table", tableOutput("table"))
)
))
server <- function(input, output, session) {
}
shinyApp(ui, server)
编辑:
按照本教程并使用闪亮的标签功能:
library(shiny)
library(tidyverse)
ui <- fluidPage(
mainPanel(
tabsetPanel(type = "tabs",
tabPanel("Plot",
column(width = 6,
plotOutput("plot")),
column(width = 6, align = "center",
tags$style(HTML('
.verticalcenter {
display: table-cell;
height: 400px;
vertical-align: middle;
}')),
tags$div(class = "verticalcenter", img(src = "image.png", height = "140px", width = "140px"))
)),
tabPanel("Summary", verbatimTextOutput("summary")),
tabPanel("Table", tableOutput("table"))
)
))
server <- function(input, output, session) {
output$plot <- renderPlot(plot(iris$Sepal.Length, iris$Petal.Length))
}
shinyApp(ui, server)
推荐阅读
- machine-learning - 机器学习中的“性能度量 P”和“评估”有什么区别?
- ios - ARKit 获取 ARPlaneAnchor 顶点世界坐标
- javascript - 与应用程序路由和组件共享本地化包
- python - 使用 xlwings 密码保护特定的 Excel 工作表?
- python - 在 python 中构建字典
- machine-learning - 在网格搜索 (ANN) 中为超参数使用连续值
- javascript - 如何从反应状态中删除特定项目
- azure - 如何将 Azure IoT Hub 与 Flutter App 连接起来
- sql-server - 在工作室中使用 VB 更新 SQL 数据库
- c - feraiseexcept:编译器之间的不同行为以及缺乏实现定义行为的文档