Aug 13, 2021 09:05 AM
I am having difficulties getting GeoJSON data from a table to generate a Vega-Lite graphic. My table has one formula field called MapGeo which generates the GeoJSON “Feature” (ie the shape), one Feature per record. The “data” property is set as follows. Vega Lite plots the title, nothing else, just blank. No errors shown.
"data":{"values":{"field":"MapGeo","type":"json"}}
I performed a test to see if the data from the table is valid. I copy-pasted the features from each record and set to static data (not from the table). That worked! Below is the static configuration that works, showing two rectangles.
{
"$schema": "https://vega.github.io/schema/vega-lite/v5.json",
"title": "Test GeoJSON",
"width": "container",
"height": "container",
"data":{"values":[
{ "type": "Feature",
"geometry": {
"type": "LineString",
"coordinates": [[2,3],[4,3],[4,5],[2,5],[2,3]]
}
},
{ "type": "Feature",
"geometry": {
"type": "LineString",
"coordinates": [[0,0],[5,0],[5,2],[0,2],[0,0]]
}
}
]},
"mark": {
"type": "geoshape",
"fill": "#4cc09d",
"stroke": "#757575",
"strokeWidth": 2.5
}
}
However, I need to pull the data from the table, cannot be static. What am I missing?
My suspicion is that the “data” property is not setup correctly and/or that the data coming from the table is wrapped up in additional JSON; which I cannot see in Vega-Lite. Probably need to reference some additional properties to map the data to the feature.
Any suggestion would be appreciated.
Example of the output…
Aug 17, 2021 11:43 AM
I am starting to get the sense that perhaps the formula field is delivering text instead of JSON; Vega-Lite unable to parse or just ignores the data since it’s not an object. Very difficult to diagnose when the Vega-Lite graphics is blank and no errors are present.
Aug 18, 2021 08:57 AM
Correct. If you’re using concatenation in a formula to build an output string that looks like JSON, it’s still just a string when passed to an app. I’ve not used the Vega-Lite app myself, so I can’t offer more specific guidance on how to get it to work. Perhaps @Bill.French can offer some assistance?
Aug 18, 2021 10:16 AM
Close.
I think it may be Vega itself that is undertaking the [assumed] task of serializing the formula-generated data into an object that it can plot. Since the field is always recalculated, this could be causing the issues.
Perhaps the parser is smart enough to see a fully-baked serialized string (i.e., static JSON) but barfs on any string that uses formula functions in a late-binding process.
Idea - try copying the dynamically-generated features column into another text column and testing it again. If this works, you simply need a script block that copies the features column by value into a static data column that Vega is delighted to render.
And if the the script block actually works, it will demonstrate how you can abandon the formula approach altogether.
This demonstrates a long-held disenchantment I’ve had with formula fields; they really aren’t fields. Instead, they’re computational conditionals that are rendered at the last minute unlike spreadsheet fields which are like binary objects; they can have a static value based on a dynamic formula. I hate this aspect of Airtable’s architecture because it rules out the ability for a field to contain a value and optionally update based on a formula.
Aug 23, 2021 07:03 AM
Thanks for the tips @Bill_French and @Justin_Barrett, much appreciated.
I performed some additional testing by manually copying the dynamic generated data into a long text field as suggested. Also tried a single line text field since the JSON code is rather short. Neither worked. I did double check the data via static configuration to make sure nothing was wrong with the JSON data set.
In addition, I also tried fetching the GeoJSON data via a URL instead of the table. That also produced nothing. As a test, I copy-pasted the data from the URL into the Vega Lite for static configuration JSON. The static configuration works.
Aug 23, 2021 08:13 AM
My hunch - you have a serialization issue. Is the JSON content you are storing into the text field in object or stringified format? Can you edit this JSON using the JSON editor in Airtable?
Aug 23, 2021 10:50 AM
I am under the impression that a text field can only contain a stringified JSON, not an object. Else, I don’t know how to force it to be an object instead of text. Perhaps AT needs a JSON Object field type to make this happen.
I did try the JSON Editor method to modify the code in the text field(s) as suggested, making sure the editor saved and there were no errors.
I also tried creating a view with a single record … just in case it was getting hung up trying to generate the output from multiple records. Also tried wrapping the single record into a FeatureCollection in case Vega was looking for the additional JSON wrapper. Yes, also used the JSON Editor app for this.
So far I have the same results, just a blank interface showing the title, no graphics, no errors.
Aug 23, 2021 11:23 AM
Can you share a base with just a sample table that demonstrates the failing configuration. Happy to take a look. If so, share to bfrench@globaltc.com (my pro account).
Aug 23, 2021 11:44 AM
Sample table shared. Dashboard 1 has the apps.
Aug 23, 2021 01:37 PM
Thanks Bob! I can’t do much in the way of debugging without the ability to inspect the field configurations and perform read/write operations. It won’t even allow me to change the settings in Vega -