简体   繁体   中英

Positioning the text within Action Button in R shiny

I want to fit Resource Activity text within the given button such that Activity comes below the Resource in the button. Currently the complete word gets hidden because of less space of the button and I do not want to increase the space. Please help.

## app.R ##
library(shiny)
library(shinydashboard)

ui <- dashboardPage(
dashboardHeader(),
dashboardSidebar(),
dashboardBody(

actionButton("buttonresinvthree", "Resource Activity",style="color: 
#000000; width:8%; ")
)
)
server <- function(input, output) { }
shinyApp(ui, server)

按钮快照

The following works for me:

## app.R ##
library(shiny)
library(shinydashboard)
library(tableHTML)

ui <- dashboardPage(

 dashboardHeader(),
 dashboardSidebar(),
 dashboardBody(
  tags$head(tags$style(make_css(list('.btn', 'white-space', 'pre-wrap')))),
  actionButton("buttonresinvthree", HTML("Resource\nActivity"),
               style="color: #000000; width:8%; ")
 )
)

server <- function(input, output) { }

shinyApp(ui, server)

I added tags$head... to add CSS to the button (class btn) and used \\n for the break line between Resource\\nActivity .

The result looks like this:

在此处输入图片说明

Set white-space to normal:

## app.R ##
library(shiny)
library(shinydashboard)

ui <- dashboardPage(
dashboardHeader(),
dashboardSidebar(),
dashboardBody(

actionButton("buttonresinvthree", "Resource Activity",style="color: 
#000000; width:8%;white-space:normal;font-size:.8vw;")
)
)
server <- function(input, output) { }
shinyApp(ui, server)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM