Hi Community.
I continue to try to re-convert notebooks back to HTML. In this process, I discovered an oddity:
It doesn’t work if I try D3.csv to transform a CSV to an array within the script:
var url_source = d3.csv('https://...')
var input = document.getElementById('exampleInputEmail3')
input.value = url_source[0].url_orig;
I get the error: TypeError: Cannot read property 'url_orig' of undefined
(and I know url_orig
is a property of the referenced url_source
array… you can see this in the notebook linked at the bottom).
It does, however, work when I define a CSV in the script element:
var name = d3.csvParse(`email_name,
Name1,
Name2,
Name3`)
var input = document.getElementById('exampleInputEmail1')
input.value = name[0].email_name;
And it also works if I use D3.csv to transform a CSV to an array, then reference the array:
var url = external_data
var input = document.getElementById('exampleInputEmail2')
input.value = url[0].url_orig;
external_data = d3.csv('https:...')
Two questions:
- Any insight as to why I can in-line a csv, or reference an array created with d3.csv in another cell, but I can’t d3.csv an externally-hosted CSV in within the same cell / script?
- How do I correctly write a ‘combined’ script that both reads in the external array and then runs the function? That is, I in regular HTML, I can’t seem to do either of these two things:
option 1 won’t work in HTML – same as Observable:
<script>
var url = d3.csv('https://...')
var input = document.getElementById('exampleInputEmail1')
input.value = url[0].url_orig;
</script>
option 2 won’t work in HTML - though OK if separate Observable cells
<script>
var url = d3.csv('https://...')
</script>
<script>
var url2 = url
var input = document.getElementById('exampleInputEmail1')
input.value = url2[0].url_orig;
</script>
Here’s a notebook reproducing the successes and errors discussed above.
Thanks in advance for your insights!!