I want to load neo4j graph with the search controls getting data from aura db
To upload files, please first save the app
import streamlit as st
from streamlit_neovis import streamlit_neovis
from neo4j import GraphDatabase
st.set_page_config(layout="wide")
# Neo4j connection settings
# Replace these with your actual Aura DB credentials
NEO4J_URI = st.secrets.get("NEO4J_URI", "neo4j+s://<your-aura-instance>.databases.neo4j.io")
NEO4J_USER = st.secrets.get("NEO4J_USER", "neo4j")
NEO4J_PASSWORD = st.secrets.get("NEO4J_PASSWORD", "<your-password>")
# Initialize connection
driver = GraphDatabase.driver(NEO4J_URI, auth=(NEO4J_USER, NEO4J_PASSWORD))
st.title("Neo4j Graph Visualization")
# Search controls
st.sidebar.header("Search Controls")
search_term = st.sidebar.text_input("Search by name")
limit = st.sidebar.slider("Result limit", 1, 100, 20)
# Build Cypher query based on search parameters
cypher_query = """
MATCH (n)
WHERE n.name =~ $search
RETURN n
LIMIT $limit
"""
params = {
"search": f"(?i).*{search_term}.*", # Case-insensitive search
"limit": limit
}
# Define the visualization configuration
config = {
"containerId": "neovis",
"neo4j": {
"serverUrl": NEO4J_URI,
"serverUser": NEO4J_USER,
"serverPassword": NEO4J_PASSWORD,
},
"visConfig": {
"nodes": {
"shape": "circle",
"size": 25,
"font": {"size": 14}
},
"edges": {
"font": {"size": 12},
"arrows": {"to": {"enabled": True}}
}
},
"labels": {
"*": {
"label": "name",
"[value]": "pagerank",
"schemes": {
"fill": ["#68b9fe", "#506ee5"]
}
}
},
"relationships": {
"*": {
"thickness": "weight",
"caption": True
}
},
"initialCypher": cypher_query,
}
# Render the graph
try:
streamlit_neovis(
config,
height="600px",
query=cypher_query,
query_params=params
)
except Exception as e:
st.error(f"Error connecting to Neo4j: {str(e)}")
st.info("Please make sure you have provided valid Neo4j Aura credentials in your secrets.")
Hi! I can help you with any questions about Streamlit and Python. What would you like to know?