HTML widgets cannot be represented in plain text (need html)

@[TOC](HTML widgets cannot be represented in plain text (need html))

Recently, it was found that using the DT package in vscode reported an error, and html could not be displayed

I found a similar problem on stackoverflow and
gave the following solution
to download the following package:

 install.packages("htmlwidgets")

Then use the following code

library(IRdisplay)
htmlwidgets::saveWidget(m, "m.html")
display_html('<iframe src="m.html" width=100% height=450></iframe>')

Where m is what you want to display, this will generate an html file, if you don't want to generate html use the following code

rawHTML = base64enc::dataURI(mime = "text/html;charset=utf-8", file = "m.html")
display_html(paste("<iframe src=", rawHTML, "width=100% height=450></iframe>", sep = "\""))
unlink("m.html")

Finally, the original answerer integrated it into a function

embed = function(x, height) {
    
    
    library(IRdisplay)
    tmp = tempfile(fileext = ".html")
    htmlwidgets::saveWidget(x, tmp)
    rawHTML = base64enc::dataURI(mime = "text/html;charset=utf-8", file = tmp)
    display_html(paste("<iframe src=", rawHTML, "width=100% height=", height, "id=","igraph", "scrolling=","no","seamless=","seamless", "frameBorder=","0","></iframe>", sep = "\""))
    unlink(tmp)
}

Effects of my use
insert image description here
Insert image description here

Guess you like

Origin blog.csdn.net/qq_54423921/article/details/130460323