New to Dataiku DSS? Try out our NEW Quick Start Programs today and get onboarded on the product in just one hour! Let's go

can we use python to read HTML control in webapp

Solved!
ananth
Level 3
can we use python to read HTML control in webapp

Hi,

do we have any option to read HTML control text and value in python in /DKU_TSHIRTS/webapps?

also can we create project from webapp? any example would be helpful

 

0 Kudos
1 Solution
Liev
Dataiker
Dataiker

Hi @ananth 

If you need to make values from UI available to your backend, you will need to make use of some JS in order to pass those values into a backend endpoint. The endpoint will use those, perhaps with other computations in order to generate a response. 

JS then will, if successful (or unsuccessful) update UI.

For example in HTML

<div>
  <input type="text" id="input_field" value="some_value">
</div>

 

Then in JS perhaps you want to capture when someone clicks on this (or other events)

$('#input_field').on('click', function () {
  input_value = $(this).val();
  $.getJSON(getWebAppBackendUrl('/do_something?input_value=' + input_value), function(data) {
    do_something_in_UI();
  });
});  

 

then in Python backend 

from flask import request
import json

@app.route('/do_something', methods = ['GET'])
def do_something():
    input_value = request.args.get('input_value')
    return json.dumps(some_dict_response)

 

Please treat the above as pseudocode to illustrate the general flow, hope this helps!

View solution in original post

4 Replies
Liev
Dataiker
Dataiker

Hi @ananth 

If you need to make values from UI available to your backend, you will need to make use of some JS in order to pass those values into a backend endpoint. The endpoint will use those, perhaps with other computations in order to generate a response. 

JS then will, if successful (or unsuccessful) update UI.

For example in HTML

<div>
  <input type="text" id="input_field" value="some_value">
</div>

 

Then in JS perhaps you want to capture when someone clicks on this (or other events)

$('#input_field').on('click', function () {
  input_value = $(this).val();
  $.getJSON(getWebAppBackendUrl('/do_something?input_value=' + input_value), function(data) {
    do_something_in_UI();
  });
});  

 

then in Python backend 

from flask import request
import json

@app.route('/do_something', methods = ['GET'])
def do_something():
    input_value = request.args.get('input_value')
    return json.dumps(some_dict_response)

 

Please treat the above as pseudocode to illustrate the general flow, hope this helps!

View solution in original post

ananth
Level 3
Author

Hi @Liev , thank you! this works.

moumita_biswas
Level 1
Level 1

I have a similar issue, can you please, guide us where that JS code 

 we have to write?

M.Biswas

 

0 Kudos
ananth
Level 3
Author

Hi @moumita_biswas ,

 

you have to have it updated in /libedition/localstatic "Static Web Resources"

and have that referred in your HTML as <link rel="stylesheet" href="/local/static/CSS//bootstrap.css" />

 
 

 

0 Kudos
A banner prompting to get Dataiku DSS