Sign up to take part
Registered users can ask their own questions, contribute to discussions, and be part of the Community!
Registered users can ask their own questions, contribute to discussions, and be part of the Community!
Hi,
I trying to create a web app in which I can enter data via some form. The data should be processed via some Python snippet. But so far it is not working. Can somebody explain to me what I am doing wrong.
Attached my code and part of the error message.
HTML:
<link rel="stylesheet" href="/static/public/styles/1.0.0/dku-styles.css" />
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Einfache Webanwendung</title>
</head>
<body>
<h1>Einfache Webanwendung</h1>
<form id="calcForm">
<label for="number">Geben Sie eine Zahl ein:</label>
<input type="number" id="number" name="number" required><br><br>
<button type="submit" id="submit">Berechnen</button>
</form>
<div id="resultDiv"></div>
</body>
JS:
document.addEventListener('DOMContentLoaded', function () {
const form = document.getElementById('calcForm');
const resultDiv = document.getElementById('resultDiv');
form.addEventListener('submit', function (e) {
e.preventDefault();
const number = parseFloat(document.getElementById('number').value);
const test = await fetch(getWebAppBackendUrl('/calculate'), {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({number}),
});
document.getElementById("resultDiv").innerHTML = test;
Python:
import dataiku
import pandas as pd
from flask import Flask, render_template, request, jsonify
import json # Import the json module
@app.route('/calculate')
def calculate():
test = request.args
return json.dumps({"status" : "ok" , "num" : test})
Part of my error message is:
"message":"Required request parameter \u0027projectKey\u0027 for method parameter type String is not present"
Operating system used: Linux
There is a good example on how to use HTML Apps to retrieve a Dataset in the Knowledge site. I suggest you start with copying that, get it working and modify it after that:
https://knowledge.dataiku.com/latest/data-viz/webapps/tutorial-standard-html.html
Also there is this example on the Developer site:
https://developer.dataiku.com/latest/tutorials/webapps/standard/basics/index.html