微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

R - Shiny - 如何在井面板中的单行中对齐按钮/图标?

如何解决R - Shiny - 如何在井面板中的单行中对齐按钮/图标?

我在井面板中放置了 3 个按钮图标。

问题是所有 3 个图标都没有出现在一行中(“屏幕截图”图标出现在第一行,而接下来的 2 个图标出现在第二行)。

我尝试与“fixedRow”和“style”对齐,但无法实现。

谁能帮我做这件事?

谢谢...

脚本:

TableA = data.frame(Product = c('iPhone','Macbook','Airpod','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",icon = icon("file-excel"),class = "butt1",tags$head(tags$style(".butt{background-color:white;} .butt1{color: #217346 !important;}"))),downloadButton(outputId = "SummaryPdfDownload",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",file)})

  }


############

shinyApp(ui = ui,server = server)

输出

enter image description here

注意: 请忽略 excel 和 pdf 下载的“服务器”参数(output$SummaryExcelDownload 和 output$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")),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",actionButton("btn32",div(style="display: inline-block; width: 65px ;",actionButton("btn33","row"))
      )
      
)

body <- dashboardBody()

ui = dashboardPage(header,sidebar,body)

server <- function(input,output) {}

shinyApp(ui,server)

output

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。