How to make column heading letters bold in rhandsontable in shiny

给你一囗甜甜゛ 提交于 2019-12-21 06:36:20

问题


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.



来源:https://stackoverflow.com/questions/43874347/how-to-make-column-heading-letters-bold-in-rhandsontable-in-shiny

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!