How to make column heading letters bold in rhandso

2020-06-30 02:19发布

问题:

How to make column heading bold text in rhandsontable in shiny package of r?

I have a rhandsontable in shiny that I want to make bold the text in the header. How can I do it? Does anyone know?

回答1:

You can add some style to your table as so:

library(shiny)
library(rhandsontable)

ui <- fluidPage(
  rHandsontableOutput("table1"),
  tags$style(type="text/css", "#table1 th {font-weight:bold;}")
)

server=function(input, output, session) {

  output$table1 <- renderRHandsontable({
    rhandsontable(mtcars,rowHeaders=F)
  })
}

shinyApp(ui,server)



回答2:

rhandsontable is an interface to the Handsontable.js library, so it's possible to customize it using CSS. Take the following data frame:

DF = data.frame(column.one = 1:10,
                column.two = TRUE)

rhandsontable(DF)

It looks like this without any customization.

But if you specify using CSS, you can reference it:

DF = data.frame(column.one = 1:10,
                column.two = TRUE)

func = "function (col) {  # custom CSS
  switch (col) {
    case 0:
      return '<b>Bold</b> and <em>Italics</em>';

    case 1:
      return '<em>Bold</em> and <b>Italics</b>';
   }
 }"

 rhandsontable(DF, colHeaders = htmlwidgets::JS(func))

And you end up with this.

Make sure to specify the colHeaders argument when you call the rhandsontable function.