Closed shizidushu closed 6 years ago
I find a better way to do with htmlwidget.
Extract x
from the htmlwidget object then serve is as unboxedJSON. Finally, render it in javascript.
I just test it with recharts
library but I guess this approach applies to other htmlwidget based library.
Thanks to recharts document. I got some idea about how a htmlwidget library was constructed after reading it.
#' json 1
#' @serializer unboxedJSON
#' @get /json1
function(){
library(recharts)
require(plyr)
series = list(list(
name = 'Sales',
type = 'bar',
data = c(5, 20, 36, 10, 10, 20)
))
# 定义坐标轴部分
ext = list(
xAxis = list(list(
data = c('shirt','cardign','chiffon shirt','pants','heels','socks')
)),
yAxis = list(list())
)
# 绘制
p <- ePlot(series, ext)
p$x
}
I was also having issue with this. Looked at a example that Jeff Allen wrote for his webinar on plumber.
Looks like an easy way is to create a empty
It would look something like this.
<html>
<head></head>
<body>
<iframe id="da-iframe" width="100%"></iframe>
<script>
var frame = document.getElementById("da-iframe")
iframe.src = "http://localhost:9999/cool-api-name"
</script>
</body>
</html
In my experience, it's easy to use
It's quickly to get the json part from api and then plot it using the corresponding JS library like plotly. And the generated HTML is usually very large and takes more time to fetch it.
I want to create a api return htmlwidget and then use it in my own html/js file.
It is easy to do the first part with
@serializer htmlwidget
I want to fetch the api and then load the htmlwidget into my html.
After searching with Google, I only find to use
iframe
orobject
tag to do it like the following.But the ideal way in my mind to load it is:
I spend a lot of time to figure out it but without sucess. (I don't know much about html/javascript)
Can someone help me with this?