Download and Install the Plotly Database Connector App
Launch and Connect
Having launched the app, select Postgres by clicking on its icon.
Enter your username, password, database server name (host) and its port number. Lastly, enter an initial database to which you want to connect, you may change it once your credentials have been accepted. In this case we are connecting to plotly_datasets.
Have no database? Try it out with our read-only Postgres database.
NOTE: If you are running your database locally, the host input field can stay empty since its default value is 'localhost'. Similarly, if your database is setup on port number 5432, you may leave the port input field empty as well. If your database is setup on a remote server, simply copy the endpoint name into the host input field and enter the remote server's port number on which your database is located.
Finally, click on the connect button!
Once connection is established, your connection credentials will be saved and greyed out to avoid unintentional changes. If you wish to modify your connection, click on edit credentials.
Preview Your Tables
A dropdown menu will appear. The options are the tables of the database previously selected. Select the table you wish to preview (see the top 5 rows of the table). For this example, let's select the 2011 data for USA agricultural exports which is the table named 'us_ag_exports_2011'
Scroll down to to see the full table if it does not fit in the preview window. In this example we will look into beef exports, and by looking at the column names (we have 'code' and 'beef') and the data formatting (state codes and integers respectively), we should be confident that we can accomplish a visualisation that can compare the states based on their beef export in Plotly.
Send a Query to Your Database
Having connected your app, visit Plotly Chart Creator and click on import data in the top right corner.
Choose SQL from the options on the top.
If you have not setup your connector to use HTTPS protocol, you do not need to modify any of the options. See HTTPS tutorial to setup your connector to use the HTTPS protocol. Once done, come back to this point and select the HTTPS option.
Click on Connect
The modal will close and a new panel will be added to your Plotly Chart Creator.
On the right, your available connections from the Plotly Database Connector will be displayed. If you have more than one, make sure you select the database connection that you want to use when writing the query.
Once your query is finalized, click Run Query. If you wish to set your query on a schedule to keep your grid's data updated to the latest entries of your database, visit our schedule a query tutorial.
Making a plot!
Let's visualize the beef exports by state on a map. On the left side, the GRAPH tab should be selected. Here you can choose the Chart Type drop down menu. Choose Choropleth. As for Locations, choose the state column. Finally, set the Values to be the beef column.
Since our code column data is in three letter state codes, select the Location Format to be USA State Abbreviations. We are only looking at USA data here, so for the Map Region option select USA. Finally, let's keep it simple and keep the Projection option as the default Albers USA. Come back later to explore more options.
Look to the right! You graph should be already updated. Why not add a title? Click into the empty field above the garph and enter a description.
Let's not lose all this work! Let's save the graph. Click on the SAVE tab on the left.
You will be prompted to choose your privacy settings for this graph and data. There is nothing here to classify, let's simply set both plot and data to public. Click SAVE.
Let's share this interactive plot with a friend or a coworker (or both)! Click on the SHARE tab on the left.
The fastest way is to send the Shareable Link, copy and paste it into your favorite e-mail or other communication service. Try out our Twitter, Facebook and Google+ links as well or embed it into your website by obtaining the iframe link in the Embed tab. If you set the settings to public previously, your friend or coworker will be able to view it even without an account and give you feedback.