转换的R图像,以基地64 [英] Convert R image to Base 64

查看:217
本文介绍了转换的R图像,以基地64的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在做一些决策树的情节所看到如下

I have been doing some decision tree plot as seen below

library(party)
irisct <- ctree(Species ~ .,data = iris)

plot(irisct,type="simple")

但现在我想看到的图像的基础上64,所以我可以保存图形成JSON。

But now I want to see the base 64 of the image so I can save the graph into JSON.

或者有另一种方式来发送R图像到web?

Or is there another way to send R image into the web?

推荐答案

我并不确切地知道你想要什么来完成,但这里有一个例子:

I don't know exactly what you want to accomplish, but here is an example:

# save example plot to file
png(tf1 <- tempfile(fileext = ".png")); plot(0); dev.off()

# Base64-encode file
library(RCurl)
txt <- base64Encode(readBin(tf1, "raw", file.info(tf1)[1, "size"]), "txt")

# Create inline image, save & open html file in browser 
html <- sprintf('<html><body><img src="data:image/png;base64,%s"></body></html>', txt)
cat(html, file = tf2 <- tempfile(fileext = ".html"))
browseURL(tf2)

在这里输入的形象描述

这篇关于转换的R图像,以基地64的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆