How to make column heading letters bold in rhandso

2020-06-30 01:47发布

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?

2条回答
我想做一个坏孩纸
2楼-- · 2020-06-30 02:26

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)

enter image description here

查看更多
Juvenile、少年°
3楼-- · 2020-06-30 02:33

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.

查看更多
登录 后发表回答