neo4j / neo4j-browser

Neo4j Browser is the general purpose user interface for working with Neo4j. Query, visualize, administrate and monitor the database.
https://neo4j.com
GNU General Public License v3.0
689 stars 348 forks source link

Configuring a Neo4j Browser with a default custom GRASS style #171

Closed dhimmel closed 7 years ago

dhimmel commented 8 years ago

I've created a public read-only instance of our Neo4j database at http://neo4j.het.io/ (thanks @jexp for the help). I'd like to have a custom GRASS style applied to every browser instance by default.

On StackOverflow @ikwattro mentioned that:

The style is set in the browser local storage, I'm afraid all users will have to issue the :style command.

So I could always instruct users to run:

:style https://raw.githubusercontent.com/dhimmel/hetionet/383152be2c07f8f5427dd7069535c82b0c5e8d85/hetnet/neo4j/graphstyle.grass

Is there an automated workaround, so users don't have to execute this command? If not, then I'd like suggest a feature request to couple a specific Neo4j database with a custom style. It seems like styles make sense on a per database level, rather than a per browser level. Or perhaps on a per database per browser level, but with a database default.

oskarhane commented 8 years ago

Sure, you can set the server config

browser.post_connect_cmd=style https://raw.githubusercontent.com/dhimmel/hetionet/383152be2c07f8f5427dd7069535c82b0c5e8d85/hetnet/neo4j/graphstyle.grass

in the file neo4j.conf.

Untested, but should work.
Notice the lack of : before style because of the command character is a user setting so the browser takes care of prefixing that to the command.

ikwattro commented 8 years ago

@oskarhane Wow that's very cool. Correct me if I'm wrong but there is no such setting in the operations manual ?

Anyway guys, this is awesome !

oskarhane commented 8 years ago

@ikwattro you might be correct, it's a quite new feature: http://neo4j.com/release-notes/neo4j-3-0-1/
I'll put it on the docs teams wall. Thanks.

ikwattro commented 8 years ago

Thanks, you guys rock ! Shame on me for not having checked the changelog

dhimmel commented 8 years ago

Thanks @oskarhane. The browser.post_connect_cmd setting in neo4j.conf is a great feature!. I've gotten browser.post_connect_cmd=play cypher to work and pre-play the cypher guide.

However, it looks like my style command from above doesn't work even when I run it directly from the browser. I'm guessing it could be a CORS issue (as with playing guides from URL in #170). However, the failure is silent. Assuming that reading from a URL is the cause of failure, is there a way to put the GRASS file inside of the Neo4j instance's directory structure and specify a local file with :style?

oskarhane commented 8 years ago

Yes, that's probably due to a CORS issue. There's no supported way of loading a local grass file without user interaction. Pretty ugly solution, but you could load grass by giving the :style command raw grass input.

:style

node {
  diameter: 50px;
  color: #A5ABB6;
  border-color: #9AA1AC;
  border-width: 2px;
  text-color-internal: #FFFFFF;
  font-size: 10px;
}

relationship {
  color: #A5ABB6;
  shaft-width: 1px;
  font-size: 8px;
  padding: 3px;
  text-color-external: #000000;
  text-color-internal: #FFFFFF;
  caption: '<type>';
}

node.Movie {
  color: #68BDF6;
  border-color: #5CA8DB;
  text-color-internal: #FFFFFF;
  caption: '{title}';
}

node.Person {
  color: #6DCE9E;
  border-color: #60B58B;
  text-color-internal: #FFFFFF;
  caption: '{name}';
}

To put that in the conf file you probably have to replace newlines with spaces.

dhimmel commented 8 years ago

Confirming that the failure to load the style from URL was a CORS issue. My web browser console picked up the following error:

XMLHttpRequest cannot load https://raw.githubusercontent.com/dhimmel/hetionet/383152be2c07f8f5427dd7069535c82b0c5e8d85/hetnet/neo4j/graphstyle.grass. Request header field Pragma is not allowed by Access-Control-Allow-Headers in preflight response.

I plan to proceed by applying one of the workarounds, but I think a way to preload a local grass file without user interaction would be good in the longterm.

Also confirming that the one line hack (see code snippet below) works. Therefore, if #172 gets implemented, configuration with a local grass file would be less pressing.

:style node {   diameter: 50px;   color: #A5ABB6;   border-color: #9AA1AC;   border-width: 1px;   text-color-internal: #FFFFFF;   font-size: 10px; }  relationship {   color: #A5ABB6;   shaft-width: 1.5px;   font-size: 8px;   padding: 3px;   text-color-external: #000000;   text-color-internal: #FFFFFF;   caption: '<type>'; }  node.Gene {   color: #0096FF;   border-color: #FFFFFF;   text-color-internal: #FFFFFF;   caption: '{name}'; }  node.Pathway {   color: #FF9300;   border-color: #FFFFFF;   text-color-internal: #000000;   caption: '{name}'; }  node.Anatomy {   color: #008F00;   border-color: #FFFFFF;   text-color-internal: #FFFFFF;   caption: '{name}'; }  node.Disease {   color: #8E4F00;   border-color: #FFFFFF;   text-color-internal: #FFFFFF;   caption: '{name}'; }  node.Compound {   color: #FF2600;   border-color: #FFFFFF;   text-color-internal: #FFFFFF;   caption: '{name}'; }  node.CellularComponent {   color: #FF9300;   border-color: #FFFFFF;   text-color-internal: #000000;   caption: '{name}'; }  node.BiologicalProcess {   color: #FF9300;   border-color: #FFFFFF;   text-color-internal: #000000;   caption: '{name}'; }  node.SideEffect {   color: #FFFB00;   border-color: #FFFFFF;   text-color-internal: #000000;   caption: '{name}'; }  node.Symptom {   color: #A5ABB6;   border-color: #FFFFFF;   text-color-internal: #FFFFFF;   caption: '{name}'; }  node.PharmacologicClass {   color: #FF85FF;   border-color: #FFFFFF;   text-color-internal: #FFFFFF;   caption: '{name}'; }  node.MolecularFunction {   color: #FF9300;   border-color: #FFFFFF;   text-color-internal: #000000;   caption: '{name}'; } 
oskarhane commented 7 years ago

This looks like it's resolved, so I'll close this.

Khazl commented 6 years ago

I run neo4j Version: 3.3.2 in a docker container and tried to configure a default style as described above.

When i start my container with this config and run match (n) return n i see nothing. Then i run :style http://domain.com/resources/style.grassand it works... Why? That leads me to conclude that the grass file ifself (content) and the accessible of this file are not the problem. It seems that there is an error with the default style configuration. Do you have any tips to debug this? The logs are clean.

chillier commented 6 years ago

For Khazl and others: The solution is to strip carriage returns from style.grass file, (with no "play" command in the grass file). Then the config command has the "style" command -

browser.post_connect_cmd=style http://domain.com/resources/style.grass

You may will have to whitelist "domain.com" with a config statement. browser.remote_content_hostname_whitelist=*

(or domain.com)

suchetaswabhav commented 5 years ago

Hi,

Can you please tell me where can i find the neo4j.conf file. Because if i make it manually and insert like i did for .grass file and inserted it in favorites, the neo4j.conf file is not acceptable .

Error - .conf is not a valid extension.

oskarhane commented 5 years ago

@suchetaswabhav The neo4j conf file is in the database directory, under the conf/ folder.

suchetaswabhav commented 5 years ago

I use the image file to open the Neo4j browser and database ..what to do ?

suchetaswabhav commented 5 years ago

Thanks oskarhane... i found out . You get it in Graph Applications tab - > Open folder -> configuration

Evin686 commented 5 years ago

Hi,guys Is there a way to preload a local grass file? one line hack,doesn't seem to work

TheRealMarcusChiu commented 3 years ago

@Evin686 it probably broke because of this feature implementation #548

FatihSarigol commented 2 years ago

Sure, you can set the server config

browser.post_connect_cmd=style https://raw.githubusercontent.com/dhimmel/hetionet/383152be2c07f8f5427dd7069535c82b0c5e8d85/hetnet/neo4j/graphstyle.grass

in the file neo4j.conf.

Untested, but should work. Notice the lack of : before style because of the command character is a user setting so the browser takes care of prefixing that to the command.

This is great but I just wanna make a remark here because importing grass file from some websites just doesn't work, I tried 1 https and 1 http server to host my grass file but both failed, finally I hoped that it would work from github rawfiles and it did. I don't know why the other servers did not work, I can LOAD CSV files from one of them to the same NEO4J browser for instance, but when it is a :style grassfile command it just didn't access the file, regardless of my permission for the server in conf settings.

by the way, calling the grass file from the neo4j/import directory also failed, and so did the one liner style trick inside the conf file

Evin686 commented 2 years ago

  你好,我是叶文,我已经收到您的邮件啦,谢谢你的来信