Execute raw SQL using python data source with redash and display the result

Write only the main points.

Drop the redash image locally with dockerpull and start it.

docker pull redash/redash

After that, create docker-compose.yml (REDASH_ADDITIONAL_QUERY_RUNNERS is set so that python can be used)

version: '2'
services:
  server:
    image: redash/redash:latest
    command: server
    depends_on:
      - postgres
      - redis
    ports:
      - "5000:5000"
    environment:
      PYTHONUNBUFFERED: 0
      REDASH_LOG_LEVEL: "INFO"
      REDASH_REDIS_URL: "redis://redis:6379/0"
      REDASH_DATABASE_URL: "postgresql://postgres@postgres/postgres"
      REDASH_COOKIE_SECRET: veryverysecret
      REDASH_ADDITIONAL_QUERY_RUNNERS: "redash.query_runner.python"
  worker:
    image: redash/redash:latest
    command: scheduler
    environment:
      PYTHONUNBUFFERED: 0
      REDASH_LOG_LEVEL: "INFO"
      REDASH_REDIS_URL: "redis://redis:6379/0"
      REDASH_DATABASE_URL: "postgresql://postgres@postgres/postgres"
      REDASH_ADDITIONAL_QUERY_RUNNERS: "redash.query_runner.python"
      QUEUES: "queries,scheduled_queries,celery"
      WORKERS_COUNT: 2
  redis:
    image: redis:3.0-alpine
  postgres:
    image: postgres:9.5.6-alpine
    volumes:
      - /opt/postgres-data:/var/lib/postgresql/data
  nginx:
    image: redash/nginx:latest
    ports:
      - "80:80"
    depends_on:
      - server
    links:
      - server:redash

docker-compose up

docker-compose up

Then log in to redash and set the following in your postgres data source

スクリーンショット 2017-04-28 午後4.24.51.jpg

Here's how to set up a python data source. Write Modules to import prior to running the script separated by commas if there is something to import.

スクリーンショット 2017-04-28 午後4.29.06.jpg

Then, select python for datasource and enter the following in query creation

query='\
select \
    count(*) AS count \
from queries \
'

values = execute_query('postgres', query)['rows']

add_result_row(result, {'name': 'result', 'count': values[0]['count']})

add_result_column(result, 'name', '', 'date')
add_result_column(result, 'count', '', 'date')

You can output the result by pressing Execute.

スクリーンショット 2017-04-28 午後4.30.08.jpg

Don't make various reports by combining google spreadsheet, DB, GA, etc. I can go, I can go.

Recommended Posts

Execute raw SQL using python data source with redash and display the result
It is easy to execute SQL with Python and output the result in Excel
Add a Python data source with Redash
Execute the command on the web server and display the result
[Python] Read the csv file and display the figure with matplotlib
Solve the spiral book (algorithm and data structure) with python!
[In-Database Python Analysis Tutorial with SQL Server 2017] Step 6: Using the model
Data pipeline construction with Python and Luigi
Calculate and display standard weight with python
Behind the flyer: Using Docker with Python
Using Python and MeCab with Azure Databricks
Display Python 3 in the browser with MAMP
Easily exchange data between Python, R and Julia using the Feather format
[In-Database Python Analysis Tutorial with SQL Server 2017] Step 3: Data Exploration and Visualization
Working with OpenStack using the Python SDK
Send and receive image data as JSON over the network with Python
Get and estimate the shape of the head using Dlib and OpenCV with python
I'm using tox and Python 3.3 with Travis-CI
(Diary 1) How to create, reference, and register data in the SQL database of Microsoft Azure service with python
Format and display time series data with different scales and units with Python or Matplotlib
Let's play with Python Receive and save / display the text of the input form
Let's print PDF with python using foxit reader and specify the printer silently!
[In-Database Python Analysis Tutorial with SQL Server 2017] Step 2: Import data to SQL Server using PowerShell
Location information data display in Python --Try plotting with the map display library (folium)-
[Python] Let's execute the module regularly using schedule
Receive and display HTML form data in Python
Dynamically display epidemic data using the Grafana Dashboard
Interactively display algebraic curves with Python and Jupyter
Solving the Lorenz 96 model with Julia and Python
Archive and compress the entire directory with python
Display the image after Data Augmentation with Pytorch
[Python] Convert time display (str type) using "" "and"'" to seconds (float type) with datetime and timedelta
[CGI] Run the Python program on the server with Vue.js + axios and get the output data
[In-Database Python Analysis Tutorial with SQL Server 2017] Step 4: Feature extraction of data using T-SQL
Get Amazon RDS (PostgreSQL) data using SQL with pandas
Notes on HDR and RAW image processing with Python
Visualize the range of interpolation and extrapolation with python
Get the result in dict format with Python psycopg2
Send and receive Gmail via the Gmail API using Python
Write data to KINTONE using the Python requests module
Get comments and subscribers with the YouTube Data API
Install the latest stable Python with pyenv (both 2 and 3)
Display and shoot webcam video with Python Kivy [GUI]
Process csv data with python (count processing using pandas)
Investigate Java and python data exchange with Apache Arrow
Model.objects.extra to consider before using raw SQL with Django
Extract the band information of raster data with python
How to parse Java source code with AST (Abstract Syntax Tree) using ANTLR and Python
I tried the same data analysis with kaggle notebook (python) and Power BI at the same time ①
Return the image data with Flask of Python and draw it to the canvas element of HTML
[In-Database Python Analysis Tutorial with SQL Server 2017] Step 5: Training and saving a model using T-SQL
Data analysis with python 2
Data analysis using Python 0
Data cleaning using Python
Data analysis with Python
Try scraping the data of COVID-19 in Tokyo with Python
Try hitting the Twitter API quickly and easily with Python
I tried using the Python library from Ruby with PyCall
Visualize plant activity from space using satellite data and Python
[Python] Chapter 01-03 About Python (Write and execute a program using PyCharm)
[Python] LASSO regression with equation constraints using the multiplier method