Created
September 9, 2020 17:52
-
-
Save theprash/7b6163d55b199359cd0dc68c477af0fa to your computer and use it in GitHub Desktop.
An example F# notebook using .NET Interactive
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!markdown | |
## An example markdown cell. | |
* Bullet 1 | |
* Bullet 2 | |
A table: | |
| A | B | C | | |
| - | - | - | | |
| 1 | 2 | 3 | | |
| 4 | 5 | 6 | | |
#!markdown | |
Some basic F#: | |
#!fsharp | |
[1; 3; 5] | |
|> List.sum | |
#!markdown | |
Displaying a list of values: | |
#!fsharp | |
[ 1 .. 5 ] | |
#!markdown | |
Show a table: | |
#!fsharp | |
let random = System.Random() | |
let data = | |
[ | |
for i in 1 .. 5 do | |
{| Name = sprintf "Item %i" i | |
``Some random number`` = random.Next() | |
Time = System.DateTime.Now |} | |
] | |
data | |
#!markdown | |
Depend on a NuGet package: | |
#!fsharp | |
#r "nuget: XPlot.Plotly" | |
#!markdown | |
A pie chart: | |
#!fsharp | |
open XPlot.Plotly | |
[ "Pizza remaining", 3; "Pizza eaten", 5 ] | |
|> Chart.Pie | |
#!markdown | |
A bar chart using data from a previous cell: | |
#!fsharp | |
data | |
|> List.map (fun x -> x.Name, x.``Some random number``) | |
|> Chart.Bar | |
|> Chart.WithLabel "Some random number" | |
|> Chart.WithLegend true | |
#!markdown | |
Get some external data: | |
#!fsharp | |
#r "System.Net.Http" | |
let client = new System.Net.Http.HttpClient() | |
let weatherJson = | |
client | |
.GetStringAsync("http://www.7timer.info/bin/astro.php?lon=113.2&lat=23.1&ac=0&unit=metric&output=json&tzshift=0") | |
.Result | |
weatherJson | |
#!markdown | |
Parse the data and chart it: | |
#!fsharp | |
#r "nuget: Newtonsoft.Json" | |
let jObj = Newtonsoft.Json.Linq.JObject.Parse weatherJson | |
jObj.["dataseries"] | |
|> Seq.map (fun x -> x.Value<float> "timepoint", x.Value<float> "cloudcover" ) | |
|> Seq.toArray | |
|> Chart.Line | |
|> Chart.WithXTitle "Time" | |
|> Chart.WithYTitle "Cloud cover" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment