fsprojects / IfSharp

F# for Jupyter Notebooks
Other
442 stars 71 forks source link

Supporting Google Charts #118

Closed tpetricek closed 7 years ago

tpetricek commented 7 years ago

@sylvanc I think I figured out what needs to be changed to make Google charts load!

I believe we've been hitting this error on Friday and I think the second answer (specify callback) makes it work (obviously....).

sylvanc commented 7 years ago

Excellent! Are you up for adding XPlot.GoogleCharts.Paket.fsx and XPlot.GoogleCharts.fsx that sets things up to work, as the Plotly versions do?

tpetricek commented 7 years ago

I'll see if we can do it just through the FsLab formatters - that way, all you'd need to do is to #load "FsLab.fsx" - I think it should be doable without having any direct support for this in Jupyter.

(The same for Plotly - though I'm not yet sure why it does not already work out-of-the-box.)

sylvanc commented 7 years ago

Sounds good!

cgravill commented 7 years ago

Would it still be possible to chart without "FsLab.fsx" as well? It's great to share the formatters as an option, just that we don't actually use FsLab in many of our notebooks.

tpetricek commented 7 years ago

I'm sure we can support both options - though I want to make sure it can be done without modifying IFSharp directly - that way, we know that when the next cool charting library appears, we can support it just via a Nuget package.

Rickasaurus commented 7 years ago

Awesome! :)

Richard Minerich Microsoft MVP (F#) @Rickasaurus richard.minerich@gmail.com phone: 860-922-3456

On Wed, Dec 14, 2016 at 5:06 PM, Tomas Petricek notifications@github.com wrote:

I'm sure we can support both options - though I want to make sure it can be done without modifying IFSharp directly - that way, we know that when the next cool charting library appears, we can support it just via a Nuget package.

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/fsprojects/IfSharp/issues/118#issuecomment-267171811, or mute the thread https://github.com/notifications/unsubscribe-auth/AAAFlVdM7JiSUCOW8ZliFvWXA25-M2bvks5rIGhlgaJpZM4LK6sc .

cgravill commented 7 years ago

Sounds excellent, we were really glad to get the code out into .fsx files so that users could update and add their own charting libraries via Paket. If we can free that even further that would really help with the extensibility story.

ibebbs commented 7 years ago

Hey @tpetricek did you make any progress on this? I'm playing with a notebook right now and would very much like to use GoogleCharts rather than Plotly. I'd be happy to help out any way I can...

ibebbs commented 7 years ago

FWIW, I managed to successfully render a GoogleChart by amalgamating the approaches used in XPlot.Plotly.fsx and Tomas' suggested fix above into a custom display printer shown here:

open IfSharp.Kernel.App

@"<script src=""https://www.google.com/jsapi""></script>" |> Util.Html |> Display

type XPlot.GoogleCharts.GoogleChart with
  member __.GetContentHtml() =
    let html = __.GetInlineHtml()
    html
      .Replace ("google.setOnLoadCallback(drawChart);", "google.load('visualization', '1.0', { packages: ['corechart'], callback: drawChart })")

type XPlot.GoogleCharts.Chart with
  static member Content (chart : GoogleChart) =
    { ContentType = "text/html"; Data = chart.GetContentHtml() }

AddDisplayPrinter (fun (plot: XPlot.GoogleCharts.GoogleChart) -> { ContentType = "text/html"; Data = plot.GetContentHtml() })

Hope it helps.

cgravill commented 7 years ago

Thanks! I've made preliminary support for Google Charts adapted from your script @ibebbs #139

I adjusted it to save into the notebook so that output charts will last as outputs (when trusted). Also enabled all chart types, which made for a ~400KB rather than ~300KB download but means the main chart types will work without additional changes.

I've done this in the same style as the Plotly one, @tpetricek it sounds like you have a more minimal approach so adjustments are welcome!

roguetrainer commented 7 years ago

A quick thanks to all of the people working to add Google Charts to IfSharp. This will be a very useful feature. Humble end-users like me appreciate your efforts. 🥇 🥇

cgravill commented 7 years ago

Please feel free to test the current behaviour and let us if it supports everything you need. It's committed but could do with more usage before it's deployed.

btw it's only a small step from building yourself as an end-user to contributing small bits of functionality.

cgravill commented 7 years ago

Hi all, this initial support is in the beta 2 zip release. I'll close this issue now. Please do add new requests if there's adjustments or improvements for this.