theam / haskell-do

:pencil2: :bar_chart: - The Haskell code editor focused on interactive development.
Apache License 2.0
352 stars 31 forks source link

Plotly doesn't render correctly #82

Closed NickSeagull closed 7 years ago

NickSeagull commented 7 years ago

As @vertexcite noted, when writing the following code in haskell.do, one should get a correct plotly render when writing:

\`\`\`html_header
<script src="https://cdn.plot.ly/plotly-latest.min.js"></script>
\`\`\`

# HaskelDoPlay05

Write text using **markdown**.

Top-level definitions with `haskell top` blocks:

\`\`\`haskell top
import Graphics.Plotly hiding (text)
import Graphics.Plotly.Lucid
import Lens.Micro
import Data.Text (Text, pack)

f :: Int -> Int
f x = x * 2 + 30

plotData :: [(Int, Int)]
plotData = [(0,0),(0,1),(1,2),(3,4)]

\`\`\`

And evaluate them with `haskell eval` blocks:

\`\`\`haskell eval
plotly (pack "p2") [line (aes & x .~ fst & y .~ snd) plotData]
\`\`\`

\`\`\`haskell eval
show (map (f.fst) plotData)
\`\`\`

But nothing happens

NickSeagull commented 7 years ago

I've tracked the bug, and what happens, is that when we add <script> tags they don't get executed, so the Plotly JS file is not include, nor the script generated by plotlyhs is executed.

@mdibaiee you have way more experience than I do in JS, do you have any idea?

mdibaiee commented 7 years ago

@NickSeagull ah yeah, sadly setting innerHTML of a div element, which would then include script/css tags doesn't work as expected, script tags should either be appended using JavaScript (document.head.appendChild(document.createElement('script'))), or we should probably use an iframe, I'll make a PR :+1:

NickSeagull commented 7 years ago

Fixed! Closing