Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Score big with last-minute savings on the final tickets to FabCon Vienna. Secure your discount

Reply
jkfe
Frequent Visitor

How to read a file from local file system with vega-lite?

The sample vega-lite code below is getting data from an url.


Instead, I would like it to read the .csv from my local file system.


How to do that?

 

 

 

{
  "$schema": "https://vega.github.io/schema/vega-lite/v5.json",
  "data": {"url": "mydata.csv"},  
  "mark": "line",
  "encoding": {
    "x": {"field": "date", "type": "temporal"},
    "y": {"field": "price", "type": "quantitative"}
  }
}

 

 

 

Thanks.

4 REPLIES 4
Anonymous
Not applicable

Hi @jkfe ,

Depending on the information you provide, you can make the local .csv file accessible via a URL by making it available locally or via a Web server. You can follow the steps below:

1. If you are using Python version 3.x, navigate to the directory containing the .csv file on the command line and run the following command:

python -m http.server

 

2. Ensure that the web pages are served from the same local server to avoid cross-domain issues. You can modify the Vega-Lite specification to use the URL of the data source: 

{
  "$schema": "https://vega.github.io/schema/vega-lite/v5.json",
  "data": {"url": "http://localhost:8000/mydata.csv"},  
  "mark": "line",
  "encoding": {
    "x": {"field": "date", "type": "temporal"},
    "y": {"field": "price", "type": "quantitative"}
  }
}

 

Best Regards,

Ada Wang

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Thanks for answer.

That would require a local web server as I understand. Wouldn't like to have that. Want to access a file directly from the file system.

amitchandak
Super User
Super User

@jkfe , Try this in blank query in power query

 

let
Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("ZY5BDoIwEEWvQhqXCis3rL0FZVHLCKOlrXRoJIa7W9oIGrqa/vz3ZqqKvbnO4uPs4GQHveCsDJ+OyLqyKDy0Im+RuvGaoylSJaYnhQSFP+d3ZzRnx03UCIqW1b2EXqgRXJJL5y+xk30b8w/ei+GRego1/JlBS9Ogbnf2V0rYDUE1CQ5XLHCYaLKQMoLemkEozraFCz7tcTug3PHPUWhCEoQ+JPN6fRpmVtcf", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Column1 = _t]),
#"Changed Type" = Table.TransformColumnTypes(Source,{{"Column1", type text}}),
#"Parsed JSON" = Table.TransformColumns(#"Changed Type",{},Json.Document),
#"Expanded Column1" = Table.ExpandRecordColumn(#"Parsed JSON", "Column1", {"$schema", "data", "mark", "encoding"}, {"Column1.$schema", "Column1.data", "Column1.mark", "Column1.encoding"}),
#"Expanded Column1.data" = Table.ExpandRecordColumn(#"Expanded Column1", "Column1.data", {"values"}, {"Column1.data.values"}),
#"Added Custom" = Table.AddColumn(#"Expanded Column1.data", "Custom", each Table.Unpivot( Table.FromRecords({[Column1.encoding]}), {"x","y"}, "attribute", "value")),
#"Expanded Custom" = Table.ExpandTableColumn(#"Added Custom", "Custom", {"attribute", "value"}, {"Custom.attribute", "Custom.value"}),
#"Expanded Custom.value" = Table.ExpandRecordColumn(#"Expanded Custom", "Custom.value", {"field", "type"}, {"Custom.value.field", "Custom.value.type"})
in
#"Expanded Custom.value"

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

Sorry. Didn't understand the code. Appreciate if you can explain. For instance, where to inform the file name/path.

Helpful resources

Announcements
August Power BI Update Carousel

Power BI Monthly Update - August 2025

Check out the August 2025 Power BI update to learn about new features.

August 2025 community update carousel

Fabric Community Update - August 2025

Find out what's new and trending in the Fabric community.