2

How can I do something like this using R? Actually I want to set Jupyter notebook cells width to 100%. In python this code works perfectly:

from IPython.core.display import HTML, display
HTML("<style>.container { width: 100%; }</style>")

Is there any equivalent in R?

Thank you!

Community
  • 1
  • 1
ragesz
  • 6,688
  • 16
  • 64
  • 83
  • Finally I edited `/anaconda/Lib/site-packages/notebook/static/style/style.min.css` to always "force" 100% width. I added `width: 100%;` to `#notebook-container`. – ragesz Jun 14 '16 at 10:45
  • It looks like you solved the problem in a better way than using R. Thanks for this tip. You can probably create a custom css file that Jupyter will read in addition to the defaults. There are also notebook extensions that might be of interest. – Avi Jun 20 '16 at 19:46

2 Answers2

2

You can display html code in R using the display_html function e.g.,

// for full width
IRdisplay::display_html('<style>.container { width:100% !important; }</style>')

// this does not work with most sites due to same-origin policy, but no problem with local files   
IRdisplay::display_html('<iframe src="http://www.w3schools.com" width=1000, height=1000></iframe> ') 

See: SecurityError: Blocked a frame with origin from accessing a cross-origin frame

prusswan
  • 6,473
  • 3
  • 37
  • 57
SlowLearner
  • 131
  • 1
  • 9
0

Embed html code and html table to IR Kernel jupyter

  library(IRdisplay)

  display_html("your html code")

Some packages in R give tables in html format like "knitr", so if you want to put this tables in the notebook:

library(knitr)
library(kableExtra)

dt <- mtcars[1:5, 1:6]
options(knitr.table.format = "html") 
html_table= kable(dt) %>%
   kable_styling("striped") %>%
   add_header_above(c(" " = 1, "Group 1" = 2, "Group 2" = 2, "Group 3" = 2))

display_html(toString(html_table))
Pablo Vilas
  • 314
  • 2
  • 10