Giter Club home page Giter Club logo

graphql-shiny-template's Introduction

GraphQL -- Shiny Application

Welcome! This is a template for establishing a local GraphQL API endpoint and leveraging that to pull data into a locally-ran Shiny Application (RStudio). Once the foundation is running locally, it should be easy enough for you to deploy it on a cloud resource or shared server.

This code assumes that the database driving the API is a graph database in Neo4j, but you could substitute in your other database instead.

With that, let's begin!

1. Clone this repository.

Make sure this template code is on your machine.

2. Install requisite packages and software.

To start, download and install:

  • Neo4j: database foundation
    • You don't need the Desktop application, you can go through Browser or Sandbox instead.
    • If you're not using Neo4j as your database, don't worry about it!
  • Node.js and NPM (the Node Package Manager): used to run the GraphQL API
  • RStudio: used to run the Shiny Application

Once you have Node.js installed, navigate to your project folder and initialize the Node project:

npm init --y

# only if you're using Neo4j, again!
npm install @neo4j/graphql graphql apollo-server neo4j-driver neo4j-graphql-js

You'll also need to make sure you have a database in Neo4j created :)

The RStudio setup will come later.

3. Create and run your GraphQL playground.

This is where the template's index.js file comes in.

You will need to substitute in the bolt URL and port, username, and password associated with your Neo4j database. You do not need to enter your database schema, as that is inferred with the neo4j-graphql-js package.

Now, spin up your Neo4j databases and run this file using node index.js. Now, if you visit http://localhost:4000 in your web browser, you'll see the GraphQL Playground. You can run some test GraphQL queries to see how it responds.

4. Connecting to the Shiny Application.

Now that we have a local API endpoint created, time to connect it with the Shiny app.

This template comes with starter code for a Shiny app, adapted from this great dashboard template. However, if you already have an application built, just substitute in your project for the existing one.

Open up the Shiny app in RStudio by clicking on app.Rproj.

In global.R, you'll notice the inclusion of the ghql package, which is how we will connect to the API and execute queries.

In the server.R file, the ghql package uses the GraphQL client to establish an endpoint at the GraphQL Playground URL. If your URL is different, substitute that here.

link <<- 'http://localhost:4000/'
conn <<- GraphqlClient$new(url = link)

An example query is provided, but you'll also want to substitute in something relevant to your database, otherwise you'll receive an error.

# Run a query
execute_query('
query SampleQuery {
actors{
    name 
    birthday
    num_movies
}
}
')

The execute_query function shows the different possibilities in formatting data after retrieval -- raw JSON, flattened JSON, R dataframe, and a rendered datatable.

Happy coding!

graphql-shiny-template's People

Stargazers

Pruthvi Swamy avatar  avatar

Watchers

Madison Ostermann avatar

Forkers

pseegaha

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.