r - R - Shiny - 如何在 Wellpanel 的单行中对齐按钮/图标?
问题描述
我在 Wellpanel 中放置了 3 个按钮图标。
问题是所有 3 个图标都没有出现在一行中(“屏幕截图”图标出现在第一行,而接下来的 2 个图标出现在第二行)。
我尝试与“fixedRow”和“style”对齐,但无法实现。
谁能帮我做到这一点?
谢谢...
脚本:
TableA = data.frame(Product = c('iPhone', 'Macbook', 'Airpod', 'Macbook', 'Airpod', 'Macbook', 'iPhone'), East = c(1:7), West = c(5:11), North = c(15:21), South = c(24:30))
library(shiny)
library(shinythemes)
library(DT)
library(rhandsontable)
library(tidyverse)
library(tidyquant)
library(knitr)
library(gt)
library(shinycssloaders)
library(shinydashboard)
library(shinyWidgets)
header = dashboardHeader(title = 'Shiny Dashboard', titleWidth = 400)
sidebar = dashboardSidebar(
wellPanel(
"Export Options", id = "DownloadPanel", style = "background: #222d32; max-height: 145px; max-width: 220px; align-items: center",
fixedRow(tags$div(style="display: inline-block; vertical-align:center; horizontal-align:center", class = "row-fluid",
screenshotButton(selector="#TableC", label = NULL, filename = paste("Summary")),
downloadButton(outputId = "SummaryExcelDownload", label = NULL, icon = icon("file-excel"), class = "butt1",
tags$head(tags$style(".butt{background-color:white;} .butt1{color: #217346 !important;}"))),
downloadButton(outputId = "SummaryPdfDownload", label = NULL, icon = icon("file-pdf"), class = "butt2",
tags$head(tags$style(".butt{background-color:white;} .butt2{color: #b30c00 !important;}")))
))
)
)
body <- dashboardBody(uiOutput("mainpanel"))
ui = dashboardPage(header, sidebar, body)
############
server = function(input, output, session)
{
output$mainpanel = renderUI({
fluidRow(tabBox(width = 250, height = 100,
tabPanel("Apple Sales", value = 'tab1', gt_output(outputId = "TableC")%>% withSpinner(color="#3483CA", type = 1, size = 2))
))
})
TableB = as.data.frame(TableA) %>%
gt() %>%
grand_summary_rows(columns = 2:5, fns = list(TotalSales = "sum")) %>%
tab_options(grand_summary_row.background.color = "#DDEBF7") %>%
cols_width(columns = 1 ~ px(1), columns = 2 ~ px(300), everything() ~ px(100)) %>%
tab_spanner(label = "Sales", columns = 3:6)
output$TableC = render_gt(expr = TableB)
output$SummaryExcelDownload = downloadHandler(
filename = "Summary.pdf",
content = function(file) {write.xlsx(TableC, file)})
output$SummaryPdfDownload = downloadHandler(
filename = "Summary.pdf",
content = function(file) {write.xlsx(TableC, file)})
}
############
shinyApp(ui = ui, server = server)
输出:
注意:请忽略 excel 和 pdf 下载的“服务器”参数(输出 $SummaryExcelDownload 和输出 $SummaryPdfDownload),因为我仍在探索纠正相同的问题。
解决方案
尝试这个
library(shinyscreenshot)
header = dashboardHeader(title = 'Shiny Dashboard', titleWidth = 400)
sidebar = dashboardSidebar( width=300,
h5(strong("If you want to see buttons in a row, just use div()")),
fluidRow(div(
div(style="display: inline-block; width: 135px ;", screenshotButton("btn21", "Buttons")),
div(style="display: inline-block; width: 75px ;", downloadButton("btn22", "in a")),
div(style="display: inline-block; width: 75px ;", downloadButton("btn23", "row"))
)),
div(style="display: inline-block; vertical-align:center; horizontal-align:center", class = "row-fluid",
actionButton("btn11", "Buttons"),
actionButton("btn12", "in a"),
actionButton("btn13", "col")
),
div(
div(style="display: inline-block; width: 95px ;", actionButton("btn31", "Buttons")),
div(style="display: inline-block; width: 75px ;", actionButton("btn32", "in a")),
div(style="display: inline-block; width: 65px ;", actionButton("btn33", "row"))
)
)
body <- dashboardBody()
ui = dashboardPage(header, sidebar, body)
server <- function(input, output) {}
shinyApp(ui, server)
推荐阅读
- angular - Angular 2 boostrap 日期选择器禁用其他日期不起作用
- python - 使用 CNN 模型进行文本分类的预测脚本出错
- python - 使用 BS4 抓取后如何清理 HTML 标签
- express - 如何将 OAuth github 身份验证添加到 VueJS 应用程序
- excel - Excel For 如果一张纸与其他纸不能正常工作
- ruby - LoadError - 无法打开共享对象文件 - 文件存在,但它说没有这样的文件
- c# - 对象引用并用它分配新类
- python - 位置参数和 self 关键字
- c# - Ninject 中的 .NET Core DI 范围生命周期
- macos - 每当我打开 shell 时都会出现错误的解密错误