How To 5 min read

Building a simple app

Learn to kick off an Evidence.dev project, connect a CSV file, and create a simple app to show Bitcoin prices. Follow these easy steps to start analyzing and sharing your data.

Building a simple app
If you want to get somewhere, you sometimes just need to start.

Welcome to this tutorial on how to get started with Evidence.dev, a powerful tool for creating data-driven narratives. In this guide, we鈥檒l walk you through the initial setup process, how to connect to a CSV file, and how to create a simple app to visualize Bitcoin price data. By the end, you'll have a first understanding on how to use Evidence.dev to analyze and present your data.

Step 1: Setting up your project

First, let's set up a new project using Evidence.dev. Open your terminal and run the following commands:

npx degit evidence-dev/template bitcoin-app
cd bitcoin-app
npm install
npm run sources
npm run dev

What these commands do:

  1. npx degit evidence-dev/template bitcoin-app: This command clones the Evidence.dev template into a new directory named bitcoin-app.
  2. cd bitcoin-app: Navigate into the newly created project directory.
  3. npm install: Install all the necessary dependencies for your project.
  4. npm run sources: Set up the data sources for your project.
  5. npm run dev: Start the development server, allowing you to see your project in action.

Step 2: Connecting to a CSV file

For this tutorial, we will use a CSV file containing Bitcoin price data. The data should be in the following format:

Date,Open,High,Low,Close,Adj Close,Volume
2023-05-15,26931.384766,27646.347656,26766.097656,27192.693359,27192.693359,14413231792
2023-05-16,27171.513672,27299.304688,26878.947266,27036.650391,27036.650391,12732238816
2023-05-17,27035.470703,27465.927734,26600.144531,27398.802734,27398.802734,15140006925
...

Download the csv

Setting up the CSV data source

To connect this CSV file to your Evidence.dev project, follow these steps:

  1. Select the CSV Connector: Go to the Settings page in your project and select the CSV connector.
  2. Name the Source: Name your CSV data source (e.g., btc_data) and click "Confirm Changes".
  3. Add CSV Files: Copy any CSV files you want to query into the sources/[your_csv_source_name]/ directory. For example, place your Bitcoin CSV file in sources/btc_data/btc.csv.
馃憠
If you are unsure on what to do or how to do it, you can use the official evidence documentation to further your understanding.

Important notes:

Querying the CSV file

You can query your CSV file using SQL syntax. For example, to query the Bitcoin price data, you can use:

select * from btc_data.btc

Source options

You can customize the CSV reading behavior using DuckDB source options. Here are some options you might find useful:

Ensure there are no spaces in your source options and use double quotes for strings.

Step 3: Creating your first page

Now that your project is set up and connected to the CSV file, let's create your first page to visualize the Bitcoin price data. Create a new file in the pages directory named bitcoin.md and add the following content:

---
title: My first app / Bitcoin
hide_title: true
---

```btc
select
    Date as date,
    Open as open,
    High as high,
    Low as low,
    Close as close,
    CASE WHEN Date = (SELECT MAX(Date) FROM csv.btc) THEN 1 ELSE 0 END AS is_max_date

from csv.btc
```

<BigValue
  title="Close Price on Last Date"
  data={btc.filter(item => item.is_max_date === 1)} 
  value=close
  sparkline=date
/>

<LineChart 
    data={btc}  
    x=date 
    y=close
    chartAreaHeight=600
/>

What this code does:

  1. SQL Query: The SQL query within the code fence (btc) selects the columns Date, Open, High, Low, Close, and creates a new column is_max_date to identify the last date in the dataset.
  2. BigValue Component: Displays the closing price on the last date in the dataset. The data attribute filters the dataset to only include the row where is_max_date is 1.
  3. LineChart Component: Renders a line chart of the closing prices over time, with date on the x-axis and close on the y-axis. The chartAreaHeight attribute sets the height of the chart area.
馃敆
An online example can be found at https://app.fact.ist/bitcoin/.

After walking through all the steps above you should have something that looks like this.

Conclusion

In this tutorial, we walked through the process of setting up an Evidence.dev project, connecting to a CSV file, and creating a simple visualization for Bitcoin price data. With these steps, you can start exploring and presenting your data in a meaningful way. Experiment with different datasets and visualizations to make the most out of Evidence.dev. Happy coding!

Hope to see you in the next post.

FAQs

1. What is the purpose of this tutorial?

This tutorial aims to guide you through the initial setup of an Evidence.dev project, show you how to connect to a CSV file, and help you create a simple app to visualize Bitcoin prices. By the end of the tutorial, you'll have a foundational understanding of how to use Evidence.dev to analyze and present data.

2. What are the prerequisites for starting this project?

Before starting, ensure you have:

  • Node.js installed on your machine
  • The CSV file containing Bitcoin price data in the correct format
  • Basic knowledge of SQL and command line operations

3. How do I set up a new Evidence.dev project?

To set up a new Evidence.dev project, follow these steps:

  1. Open your terminal and run the following commands:

    npx degit evidence-dev/template bitcoin-app
    cd bitcoin-app
    npm install
    npm run sources
    npm run dev
  2. These commands will clone the Evidence.dev template, navigate into the project directory, install necessary dependencies, set up data sources, and start the development server.

3. How do I connect a CSV file to my Evidence.dev project?

To connect a CSV file:

  1. Go to the Settings page in your Evidence.dev project and select the CSV connector.
  2. Name your data source (e.g., btc_data) and confirm the changes.
  3. Copy your CSV files into the sources/[your_csv_source_name]/ directory. For example, place your Bitcoin CSV file in sources/btc_data/btc.csv.

4. How do I query the CSV file in Evidence.dev?

You can query your CSV file using SQL syntax. For instance, to query the Bitcoin price data:

select * from btc_data.btc

You can customize the CSV reading behavior using DuckDB source options such as header=true and delim=",".

5. Where can I see the final app?

You can view the final app online at this link. This shows the completed project with all the data visualizations and insights.

6. What resources can help me learn more about using Evidence.dev?

To learn more about Evidence.dev, you can:

  • Explore the official documentation
  • Familiarize yourself with SQL and markdown syntax
  • Join the Evidence community on Slack or GitHub for support and insights

7. What should I do if I encounter issues during setup?

If you encounter issues, refer to the official Evidence.dev documentation for troubleshooting tips. You can also seek help from the Evidence community on Slack or GitHub.

Read next

Integrating UIkit
How To

Integrating UIkit

UIkit is a lightweight, modular front-end framework perfect for rapid UI development. Learn how to integrate it with Evidence.dev for efficient, responsive web interfaces.

Using markdown
How To

Using markdown

Markdown makes writing docs easy and accesible. Learn the basics, from headers to tables, and see how it simplifies your workflow. Dive in and give it a try!