-
Notifications
You must be signed in to change notification settings - Fork 15
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Feature request] Ability to get the HTML/script in order to embed on a different site #81
Comments
(note: typing on my phone, so will keep it short) We define In addition there's a Looking at how it's done in the |
Consider the HTML template we normally use for a plot: <!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>$title</title>
<script src="https://cdn.plot.ly/plotly-latest.min.js"></script>
</head>
<body>
<div id="plot0"></div>
<script>
$scriptTag
</script>
$saveImage
</body>
</html> The main important thing is the What is fed into Plotly.newPlot('plot0', $data, $layout) which is just the plotly API on the JS side to create a new plot. Then That means the easiest way to generate insert a plotly plot into your own HTML is something like this (starting from example 16): const
n = 70
var
y = newSeq[float64](n)
x = newSeq[float64](n)
text = newSeq[string](n)
sizes = newSeq[float64](n)
for i in 0 .. y.high:
x[i] = i.float
y[i] = sin(i.float)
text[i] = $i & " has the sin value: " & $y[i]
sizes[i] = float64(10 + (i mod 10))
let plt = scatterColor(x, y, y)
.mode(PlotMode.LinesMarkers)
.markersize(15)
.toPlotJson()
# the returned `plt` is a `PlotJson` object with two fields:
# - traces: a JSON object of the traces that can just be inserted into the `$data` field
echo plt.traces.pretty()
# - layout: a JSON object for the layout that can just be inserted into the `$layout` field
echo plt.layout.pretty() From there you can just have your own code that generates your HTML and plug these (maybe not using Does that make it clear? |
That does indeed make it clearer, but I'd love to have a single procedure that would return |
I have a Raspberry Pi which is collecting temperature and humidity data with a cron-job. I wanted to display this data on a nice little website along with other things the Raspberry Pi controls. For a little chart I first thought of using Chart.js, but decided to have a look around the Nim ecosystem to see if I could find something here instead. Plotly looks cool (and I know that it uses JS to actually display the plot) and I'd want to use it, but I wish there was a way for me to get HTML which I could embed into the rest of the site. Currently only
save
is exposed which means I would have to save it to a file, then read and parse that file to get the bits I need, not great.Any feedback appreciated, I believe this should be a fairly simple feature to implement seeing how most of this functionality is already there.
The text was updated successfully, but these errors were encountered: