LDAvis
LDAvis copied to clipboard
Loading lda.json as a local file causes security issues
Generated visualization cannot be opened as a local file. It triggers an error, something like
XMLHttpRequest cannot load file. Origin null is not allowed by Access-Control-Allow-Origin
The current implementation works around this issue by starting a local webserver but generated artifact cannot be shared with other users, reopened when the local webserver shuts down, etc.
Lighter (but hackier) solution is to initialize data (validated by Adam Detrick) is to read data in as a Javascript code and use it directly in LDAvis without loading via d3.json.
Proposed changes:
-
Changed lda.json to data.js: assign JSON to const data= . It will look like:
const data = { "mdsDat": {...
-
Modify index.html:
- insert
<script src="data.js"></script>
in - change call LDAvis("#lda", json_file) to LDAvis("#lda", data)
- Modify ldavis.js
- change the first line to:
LDAvis = function (to_select, data) {
- remove lines:
d3.json(json_file, function(error, data) {
and corresponding)};
This is it. Now generated artifacts can be opened locally in any browser, shared among users, etc
Generated visualization cannot be opened as a local file. It triggers an error, something like
XMLHttpRequest cannot load file. Origin null is not allowed by Access-Control-Allow-Origin
The current implementation works around this issue by starting a local webserver but generated artifact cannot be shared with other users, reopened when the local webserver shuts down, etc.
Lighter (but hackier) solution is to initialize data (validated by Adam Detrick) is to read data in as a Javascript code and use it directly in LDAvis without loading via d3.json.
Proposed changes:
- Changed lda.json to data.js: assign JSON to const data= . It will look like:
const data = { "mdsDat": {...
- Modify index.html:
- insert
<script src="data.js"></script>
in- change call LDAvis("#lda", json_file) to LDAvis("#lda", data)
- Modify ldavis.js
- change the first line to:
LDAvis = function (to_select, data) {
- remove lines:
d3.json(json_file, function(error, data) {
and corresponding)};
This is it. Now generated artifacts can be opened locally in any browser, shared among users, etc
It works! Thanks a lot!