FSharp.Formatting icon indicating copy to clipboard operation
FSharp.Formatting copied to clipboard

Evaluation not working when using conditions

Open kMutagene opened this issue 4 years ago • 2 comments

I am trying to use conditions to render both html and ipynb from .fsx files. The content of the resulting files itself looks fine, but evaluation via (***include-it-raw***) does not work as soon as there are conditionals in the file.

Take this example from Plotly.NET (file here):

(*** hide ***)

(*** condition: prepare ***)
#r "../bin/Plotly.NET/net5.0/Plotly.NET.dll"
(*** condition: fsx ***)
#if FSX
#r "../packages/Newtonsoft.Json/lib/netstandard2.0/Newtonsoft.Json.dll"
#r "../bin/Plotly.NET/net5.0/Plotly.NET.dll"
#endif // FSX
(*** condition: ipynb ***)
#if IPYNB
#r "nuget: Plotly.NET, 2.0.0-beta1"
#r "nuget: Plotly.NET.Interactive, 2.0.0-alpha5"
#endif // IPYNB

(** 
# Bubble charts
[![Binder](https://mybinder.org/badge_logo.svg)](https://mybinder.org/v2/gh/plotly/Plotly.NET/gh-pages?filepath=bubble-charts.ipynb)
*Summary:* This example shows how to create pie and doughnut charts in F#.
let's first create some data for the purpose of creating example charts:
*)

open Plotly.NET 
  
let x = [2; 4; 6;]
let y = [4; 1; 6;]
let size = [19; 26; 55;]

(**
A bubble chart is a type of chart that displays three dimensions of data. Each entity with its triplet (x, y, size) 
of associated data is plotted as a disk. The first two values determine the disk's xy location and the 
third its size.
*)
  
let bubble1 = Chart.Bubble(x,y,size)

(*** condition: ipynb ***)
#if IPYNB
bubble1
#endif // IPYNB

(***hide***)
bubble1 |> GenericChart.toChartHTML
(***include-it-raw***)

results in this html file

note that the notebook available at the binder link works like a charm, so big thumbs up for that!

The following line should insert raw chart html when evaluated:

(***hide***)
bubble1 |> GenericChart.toChartHTML
(***include-it-raw***)

but will result in

No value returned by any evaluator

The problem seems to be specific to include-it-raw, as include-value works just fine.

kMutagene avatar Jan 17 '21 20:01 kMutagene

So with some more investigation, this was fixed on my side by adding a Newtonsoft.JSON reference to the script. While i am happy that it works now, I still think there is something wrong here, as i was running with --strict, and a missing reference should have aborted doc generation

kMutagene avatar Jan 18 '21 06:01 kMutagene

So with some more investigation, this was fixed on my side by adding a Newtonsoft.JSON reference to the script. While i am happy that it works now, I still think there is something wrong here, as i was running with --strict, and a missing reference should have aborted doc generation

Thanks, that is very subtle indeed, I was hitting the same problem I think. And yes --strict should fail in this case. I'll see if I can add that now

dsyme avatar Feb 11 '21 13:02 dsyme