knitr::opts_chunk$set( collapse = TRUE, comment = "#>" )
The function neo4j_query()
can be used to send a query to a local or remote Neo4J server. This function uses cypher-shell
to send the query to Neo4J, and so the cypher-shell
executable needs to be installed and available locally. See the README
file for further information on configuration of the cypher-shell
executable.
neo4j_query()
takes the following arguments:
con
should be a list containing three elements: address
, which should be the bolt address of the Neo4J server, and uid
and pwd
as login credentialsqry
should be a character string representing the query to be sent to Neo4Jshell_path
should be the full path to the cypher-shell
executable. The default value assumes that cypher-shell
is already in the system path. Use path.expand()
if necessary. database
specifies the database to be queried if not the default database. (For multitenancy Neo4J installations).encryption
is the encryption option passed to cypher-shell
. This may be required as explicitly 'true'
or 'false'
for older installations.Example, assuming a local Neo4J instance running the movies graph:
library(neo4jshell) neo4j_local <- list(address = "bolt://localhost", uid = "neo4j", pwd = "password") CQL <- 'MATCH (p1:Person {name: "Kevin Bacon"})-[:ACTED_IN]->(m:Movie)<-[:DIRECTED]-(p2:Person) RETURN p2.name AS Name, m.title AS Title' cypher_path <- path.expand("~/neo4j-community-4.0.4/bin/cypher-shell") neo4j_query(con = neo4j_local, qry = CQL, shell_path = cypher_path)
This query should return this dataframe:
``` {r example-output, echo = FALSE}
data.frame(Name = c("Ron Howard", "Rob Reiner", "Ron Howard"), Title = c("Frost/Nixon", "A Few Good Men", "Apollo 13"))
```
neo4j_query()
accepts multiple query statements separated by ;
. The function returns one of the following:
Paths to executable files that are provided as arguments to functions may need to be provided with appropriate extensions (eg cypher-shell.bat
).
Any scripts or data that you put into this service are public.
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.