Franklin: How to obtain output of fdplotly() as HTML string?

I would like to know how I can obtain HTML string from fdplotly() in Franklin.

This is because I what to put the HTML in an outer div so that I can create a tabular layout for plotly plots.

Imaginary code will look something like:

p = PlotlyJS.scatter()
html = fdplotly(json(p); return_as_string=true) 
# maybe there must be an option to prevent fdplotly() from 
# printing right away at this point and instead return HTML 
# string so that user can put the result in a way he likes

println("""
~~~
<div style="display:flex; flex-wrap: wrap;">
   $(html)
<div>
~~~
""")

Hello!

So for your specific use case I think you could do

fdplotly(json(p); style="display:flex; flex-wrap:wrap;") 

but granted you might want to do something specific with the string, if you look at the code it should be pretty simple to build your own: this is the string I use in fdplotly:

~~~
<div id="$id" style="$style"></div>

<script>
	var fig = $json;
	CONTAINER = document.getElementById('$id');
	Plotly.newPlot(CONTAINER, fig.data, fig.layout)
</script>
~~~

you can modify this as you’d like :slight_smile: you could also create your own function with your own specs

1 Like

@tlienart, thank you for your prompt reply!

whatever style I pass to fdplotly() is meant for that particular div that fdplotly() creates for me.
I wanted to put the auto generated div in an outer div that I define myself.

Let me try the second example; This approach is really great; I can control divs arbitrarily. Thank you again for your valuable suggestion. :slight_smile:

1 Like