glin / reactable

Interactive data tables for R
https://glin.github.io/reactable
Other
627 stars 80 forks source link

HTML inside cells #6

Closed atusy closed 5 years ago

atusy commented 5 years ago

It would be nice if we can easily toggle parsing HTML inside cells. I found a related question in Spectrum, but have no idea how to use it in R.

https://spectrum.chat/react-table/general/passing-html-in-through-accessors~36982f4c-1f49-43ab-9a97-f9128176d78f

I want to do something like

reactable::reactable(
  data.frame(
    pkg = '<a href = "https://github/com/glin/reactable">reactable</a>',
    stringsAsFactors = FALSE
  )
)

It would be nice if reactable() supports the feature by an argument like escape, inner_html, or something like that requiring boolean.

glin commented 5 years ago

Hi,

You can toggle raw HTML rendering by setting html = TRUE on a column definition:

reactable::reactable(
  data.frame(
    pkg = '<a href = "https://github/com/glin/reactable">reactable</a>',
    stringsAsFactors = FALSE
  ),
  columns = list(
    pkg = colDef(html = TRUE)
  )
)

There's no table-level setting, but to enable it for all columns, you can use the default column definition:

reactable::reactable(
  data.frame(
    pkg = '<a href = "https://github/com/glin/reactable">reactable</a>',
    stringsAsFactors = FALSE
  ),
  defaultColDef = colDef(html = TRUE)
)

Alternatively, you could use htmltools inside a cell render function like this example: https://glin.github.io/reactable/articles/examples.html#cell-renderers

atusy commented 5 years ago

Thanks! it works perfectly!!