如何调整R Shiny中actionButton的高度?附flexdashboard相关疑问
一、调整actionButton的高度
你当前通过style = "height: 60px"设置按钮高度,但可能因flexdashboard默认样式、btn-lg类的内边距影响,导致高度不符合预期。可通过以下方式优化:
方法1:精细化控制内边距与行高
在actionButton的style参数中同时定义height、line-height和padding,确保按钮文字垂直居中,高度完全符合预期:
output$UIbutton <- renderUI({ actionButton(inputId = "UIbutton", label = "Delete?", width = "100%", class = "btn-danger btn-lg", style = "height: 60px; line-height: 40px; padding: 0 16px;" ) })
方法2:移除btn-lg类,自定义尺寸
btn-lg类会添加默认内边距和字体大小,若不需要大按钮样式,可移除该类,直接通过style定义高度:
output$UIbutton <- renderUI({ actionButton(inputId = "UIbutton", label = "Delete?", width = "100%", class = "btn-danger", style = "height: 60px; font-size: 16px;" ) })
方法3:给按钮容器强制设高
用div包裹actionButton,先定义容器高度,再让按钮填满容器:
output$UIbutton <- renderUI({ div( actionButton(inputId = "UIbutton", label = "Delete?", width = "100%", class = "btn-danger btn-lg", style = "height: 100%;" ), style = "height: 60px;" ) })
二、标题间出现“true”字样的原因及解决
问题源于YAML头部的格式错误:orientation和vertical_layout属于flexdashboard::flex_dashboard的专属参数,需要缩进在该输出格式的层级下,而非与output同级。
错误的YAML格式:
--- title: "Action Button Example" author: output: flexdashboard::flex_dashboard: orientation: rows vertical_layout: scroll runtime: shiny ---
修正后的YAML格式:
--- title: "Action Button Example" author: "" output: flexdashboard::flex_dashboard: orientation: rows vertical_layout: scroll runtime: shiny ---
注:author字段若为空,建议补充空字符串"",避免YAML解析异常。
修正后,参数被正确识别,“true”字样会自动消失。
内容的提问来源于stack exchange,提问作者Volker Holzendorf
相关产品推荐
相关产品推荐

