Gramex 1.40 Release Notes

FilterHandler

FilterHandler lets you filter columns from files and databases.

Here is a sample configuration to filter data columns from a CSV file:

url:
  flags:
    pattern: /$YAMLURL/flags
    handler: FilterHandler
    kwargs:
      url: $YAMLPATH/flags.csv

Credits to @nikhil.kabbin for the contribution.

See the documentation.

FormHandler modify

FormHandler now supports applying modify on multiple datasets.

If you have multiple datasets, modify: can modify all of these datasets – and join them if required.

This example has two modify: – the first for a single query, the second applies on both datasets.

url:
  formhandler-modify-multi:
    pattern: /$YAMLURL/modify-multi
    handler: FormHandler
    kwargs:
      symbols:
        url: sqlite:///$YAMLPATH/../datahandler/database.sqlite3
        table: flags
        query: "SELECT Continent, COUNT(DISTINCT Symbols) AS dsymbols FROM flags GROUP BY Continent"
        # Modify ONLY this query. Adds rank column to symbols dataset
        modify: data.assign(rank=data['dsymbols'].rank())
      colors:
        url: $YAMLPATH/flags.csv
        function: data.groupby('Continent').sum().reset_index()
      # Modify BOTH datasets. data is a dict of DataFrames.
      modify: data['colors'].merge(data['symbols'], on='Continent')

modify: can be any expression that uses data, which is a dict of DataFrames {'colors': DataFrame(...), 'symbols': DataFrame(...). It can return a single DataFrame or any dict of DataFrames.

See the documentation.

g1 dropdown

Dropdown component that integrates well with g1.urlfilter

$.dropdown requires bootstrap-select library and its dependencies.

Examples:

<div class="container1"></div>
<script>
  $(".container1").dropdown({ data: ["Red", "Green", "Blue"] });
</script>

The above code snippet renders a dropdown with 3 options Red, Green, Blue using bootstrap-select library.

<div class="container2"></div>
<script>
  $(".container2").dropdown({ key: "colors", data: ["Red", "Green", "Blue"] });
</script>

key enables urlfilter for dropdown. If Red option is selected from dropdown, URL is appended with ?colors=Red

By default, the selected dropdown values are appended to URL query string. To append to the hash instead, use target: '#'.

<div class="container3"></div>
<script>
  $(".container3").dropdown({
    key: "colors",
    data: ["Red", "Green", "Blue"],
    target: "#",
  });
</script>

To change URL without reloading the page, use target: 'pushState'.

To use bootstrap-select options, use options:

<div class="container5"></div>
<script>
  $(".container5").dropdown({
    data: ["Red", "Green", "Blue"],
    key: "colors",
    options: {
      style: "btn-primary",
      liveSearch: true,
    },
  });
</script>
<div class="container5"></div>
<script>
  $(".container5")
    .on("load", function () {
      // Your code here
    })
    .on("change", function () {
      // Your code here
    })
    .dropdown({
      key: "colors",
      data: ["Red", "Green", "Blue"],
    });
</script>

Credits to @pragnya.reddy for the contribution.

See the documentation

Password Encryption

DBAuth now allows you to encrypt the password on client-side (browser) before submitting the credentials. @sundeep.mallu

Smart Alerts

Smart Alerts now has a video tutorial.

Following examples are updated:

MapViewer

Mapviewer tutorial is updated with g1.mapviewer usage with examples of controls, colors, click events, tooltip.

Video tutorial on Mapviewer usage is added.

Brief overview of Map tools (Mapshaper, QGIS) is provided in the tutorial.

Logviewer

Logviewer now runs in a separate thread in the background by default, allowing gramex to start faster. Metric calculations and underlying queries are updated. Logviewer Usage options and example(s) are updated.

Speech Demo

Speech recognition demo now has a speech player (talks insights to you!) using speech synthesis API. Contributed by @dhiraj.eadara

Developer Updates

g1

g1.js is upgraded to 0.9.0, which comes with

Bug fixes

Stats

Upgrade

To upgrade Gramex, run:

pip install --verbose gramex==1.40

To upgrade apps dependencies, run:

gramex setup --all

This downloads Chromium and other front-end dependencies. That may take time.