LDAvis icon indicating copy to clipboard operation
LDAvis copied to clipboard

Loading lda.json as a local file causes security issues

Open ielbert-cbi opened this issue 4 years ago • 1 comments

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:

  1. Changed lda.json to data.js: assign JSON to const data= . It will look like: const data = { "mdsDat": {...

  2. Modify index.html:

  • insert <script src="data.js"></script> in
  • change call LDAvis("#lda", json_file) to LDAvis("#lda", data)
  1. 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

ielbert-cbi avatar Mar 06 '20 00:03 ielbert-cbi

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:

  1. Changed lda.json to data.js: assign JSON to const data= . It will look like: const data = { "mdsDat": {...
  2. Modify index.html:
  • insert <script src="data.js"></script> in
  • change call LDAvis("#lda", json_file) to LDAvis("#lda", data)
  1. 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!

derbirch avatar Jan 27 '21 17:01 derbirch