Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to get Data from url using signal and following datasources are empty #2014

Closed
mathiastiberghien opened this issue Sep 16, 2019 · 4 comments · Fixed by #2022
Closed
Labels
bug For bugs or other software errors

Comments

@mathiastiberghien
Copy link

Hi,
I have issue when i try to load a data from url using signal reference.
Did I configure something wrong?
Thanks
Here's my sample: Vega Editor Sample

I you look in the data viewer:
"data_1": hard-coded values, have the expected data
"data_from_url": hard-coded url, have the expected data
"data_from_url_signal": url based on signal reference, data table is empty
"data_2": hard-coded values, data table is empty

if you add define datasources after "data_from_url_signal" the data remains empty
There are no logs indicating any failure

@roying
Copy link

roying commented Sep 17, 2019

An error is shown in the javascript console:

screenshot_vega_error

For data in JSON format, Vega expects an array of objects.
https://vega.github.io/vega/docs/data/

The data from the URL is in this format which is not what Vega expects:

{
	"cod": "200",
	"message": 0.0069,
	"cnt": 40,
	"list": [{
			"dt": 1568646000,
			"main": {
				"temp": 27.05,
				"temp_min": 26.3,
				"temp_max": 27.05,
				"pressure": 1019.99,
				"sea_level": 1019.99,
				"grnd_level": 1008.76,
				"humidity": 38,
				"temp_kf": 0.76
			},
			"weather": [{
					"id": 802,
					"main": "Clouds",
					"description": "scattered clouds",
					"icon": "03d"
				}
			],
			"clouds": {
				"all": 39
			},
			"wind": {
				"speed": 3.08,
				"deg": 317.028
			},
			"sys": {
				"pod": "d"
			},
			"dt_txt": "2019-09-16 15:00:00"
		}, {
			"dt": 1568656800,
...

The workaround is to use javascript to fetch data from the URL, process the data, and then replace the data in the Vega dataset using Vega View API:

   view.data(name[, values])

(Vega version ≥5.5) If two arguments are provided, removes the current data and inserts the input values, which can be either a single data object or an array of data objects.

https://vega.github.io/vega/docs/api/view/

@mathiastiberghien
Copy link
Author

Thanks for the answer, I'll think to use the javascript debugger now (I'm new to Vega but really enjoy it)
But in my sample, I also defined a datasource with the same url than the one using scale, but this one doesn't fail even if the query return also one object.
I was expecting that the behavior should be the same using inline url or signal url: both failing or both succeeding

@jheer jheer added the bug For bugs or other software errors label Sep 24, 2019
@jheer
Copy link
Member

jheer commented Sep 24, 2019

Thanks for sharing the issue! I agree that the two loading methods should behave similarly. I've made a minor adjustment to the Load operator in the vega-transforms package that will ensure any retrieved values are wrapped in an array if not already array-valued, such that behavior of built-in and dynamic URL loading are better aligned. This fix will be included in the next release.

@mathiastiberghien
Copy link
Author

mathiastiberghien commented Sep 24, 2019 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug For bugs or other software errors
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants