Skip to content

Commit

Permalink
saving
Browse files Browse the repository at this point in the history
  • Loading branch information
Marco Zocca committed Jan 7, 2024
1 parent d159533 commit 9f7fd1a
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 1 deletion.
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,13 @@ Load the script from CDN into the head of your HTML file:
<script src="https://cdn.jsdelivr.net/gh/ocramz/[email protected]/htmx-plotly.js" integrity="sha256-jPyGR/Ll6Vkxkef+ATkyCoqduaTA6e3r57lvOxlZmxU=" crossorigin="anonymous"></script>
```

and of course also HTMX and Plotly:

```html
<script src="https://unpkg.com/[email protected]" integrity="sha384-D1Kt99CQMDuVetoL1lrYwg5t+9QdHe7NLX/SoJYkXDFfX37iInKRy5xLSi8nO7UC" crossorigin="anonymous"></script>
<script src="https://cdn.plot.ly/plotly-2.27.0.min.js" charset="utf-8"></script>
```

### Usage

Add these attributes to a page element:
Expand Down
11 changes: 10 additions & 1 deletion index.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,16 @@
<body>


<a href="#" hx-ext="htmx-plotly" hx-post="/get-data" hx-swap="none" plot-id="my-plot"><h1>UPDATE</h1></a>
<!-- <a href="#" hx-ext="htmx-plotly" hx-post="/get-data" hx-swap="none" plot-id="my-plot"><h1>UPDATE</h1></a> -->

<form action="#" hx-ext="htmx-plotly" hx-post="/get-data" hx-swap="none" plot-id="my-plot">
<select name="veggies">
<option value="potatoes">potatoes</option>
<option value="carrots">carrots</option>
<option value="broccoli">broccoli</option>
</select>
<input type="submit" value="Submit"/>
</form>

<div id="my-plot"></div>

Expand Down
4 changes: 4 additions & 0 deletions server.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,16 @@ app.use(morgan('combined'))
// static files
var public = path.join(__dirname, '');
app.use('/', express.static(public));
// url-encoded forms
const bodyParser = require('body-parser');
app.use(bodyParser.urlencoded({ extended: true }));

app.get('/', (req, res) => {
res.sendFile(path.join(public, 'index.html'));
});

app.post('/get-data', (req, res) => {
console.log('form data: '+JSON.stringify(req.body)) // form data
const n = 3;
const x = Array.from({length: n}, (_, i) => i );
const y = Array.from({length: n}, () => Math.floor(Math.random() * 10) );
Expand Down
Empty file added server.py
Empty file.

0 comments on commit 9f7fd1a

Please sign in to comment.