Skip to content

Instantly share code, notes, and snippets.

@kMutagene
Last active May 25, 2020 07:05
Show Gist options
  • Save kMutagene/afadbd5b9cb8e6b0401e94338a2644e4 to your computer and use it in GitHub Desktop.
Save kMutagene/afadbd5b9cb8e6b0401e94338a2644e4 to your computer and use it in GitHub Desktop.
POC of PuppeteerSharp rendering a FSharp.Plotly plot
//#r "nuget: ..." is a preview feature of F#5, make sure to adapt if you dont use it.
#r "nuget: PuppeteerSharp"
#r "nuget: FSharp.Plotly"
open PuppeteerSharp
open FSharp.Plotly
[(1,2);(2,4);(3,5)]
|> Chart.Line
|> Chart.SaveHtmlAs "your/path/here"
let revInfo =
new BrowserFetcher()
.DownloadAsync(BrowserFetcher.DefaultRevision)
|> Async.AwaitTask
|> Async.RunSynchronously
let launchOptions = new LaunchOptions(Headless=true)
let browser =
Puppeteer.LaunchAsync(launchOptions)
|> Async.AwaitTask
|> Async.RunSynchronously
let page =
browser.NewPageAsync()
|> Async.AwaitTask
|> Async.RunSynchronously
page.GoToAsync("file:///your/path/here")
|> Async.AwaitTask
|> Async.RunSynchronously
page.ScreenshotAsync("your/rendered/chart/path")
|> Async.AwaitTask
|> Async.RunSynchronously
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment