I am trying to embed an interactive chart in HTML format in google-site. I made this plot using using vega-lite. To embed it in google-site from the google-sites "edit-mode", I choose Insert>Embed>Embed code
and simply paste the HTML content in the box.
The vega-lite charts take data encoded in JSOn format. One can read the input data from a JSON file hosted elsewhere other than google drive, as shown in this example: https://vega.github.io/vega-lite/docs/data.html#url. But from my experience vega-lite was unable to read the data from a json file located on google-drive.
So my question is: Can I read a json file located on google-drive (private/shared) to display an vega-lite plot on google-sites?
I hope that this would be be possible. That would be so great. It will streamline the presentation of interactive plots so much.
As an example, here's the content of an HTML file generated using vega-lite that I embed in google drive
<!DOCTYPE html>
<html>
<head>
<title>Embedding Vega-Lite</title>
<script src="https://cdn.jsdelivr.net/npm/vega@5.21.0"></script>
<script src="https://cdn.jsdelivr.net/npm/vega-lite@5.2.0"></script>
<script src="https://cdn.jsdelivr.net/npm/vega-embed@6.20.2"></script>
</head>
<body>
<div id="vis"></div>
<script type="text/javascript">
var yourVlSpec = {
$schema: 'https://vega.github.io/schema/vega-lite/v5.json',
description: 'A simple bar chart with embedded data.',
data: {
values: [
{a: 'A', b: 28},
{a: 'B', b: 55},
{a: 'C', b: 43},
{a: 'D', b: 91},
{a: 'E', b: 81},
{a: 'F', b: 53},
{a: 'G', b: 19},
{a: 'H', b: 87},
{a: 'I', b: 52}
]
},
mark: 'bar',
encoding: {
x: {field: 'a', type: 'ordinal'},
y: {field: 'b', type: 'quantitative'}
}
};
vegaEmbed('#vis', yourVlSpec);
</script>
</body>
</html>
I would like to provide the data from the json file stored on google drive and supply it to the datasets
field i.e. instead of
data: {
values: [
{a: 'A', b: 28},
{a: 'B', b: 55},
{a: 'C', b: 43},
{a: 'D', b: 91},
{a: 'E', b: 81},
{a: 'F', b: 53},
{a: 'G', b: 19},
{a: 'H', b: 87},
{a: 'I', b: 52}
]
},
I would like to get the data
from a json file on google-drive like this:
data: "https://drive.google.com/uc?export=view&id=FILE_ID"