Skip to content
Advertisement

Ηow to select a dataframe index via a dropdown menu in Flask?

Context and what I want to do :

Hi, here is an example with the iris dataset. I have imported my machine learning model, and my web-app idea is :

  • that instead of entering floating values of features in fields myself to run an iris class estimation,
  • I want to use instead the index of the dataframe in a dropdown menu.

That way, I only have to select the test set row and the model would get the x_test features automatically to do its estimation.

Problem :

My problem is that the dropdown menu appears but there is nothing I can select in it. I feel I am almost done with it, but I can’t figure out where is the problem (this is my 1st flask project), do you have any idea how to do this please? thank you very much for your kind help, here is my code :

My code :

– app.py :

JavaScript

– index.html :

JavaScript

Advertisement

Answer

Not sure how to answer your question. Copy paste this code and tell me if it worked the way you wanted.

I suppose these items did not show up because you’ve opened "/" route instead of "/predict", or maybe because your .index_to_list() method did not return list at all.


main.py:

JavaScript

index.html:

JavaScript
User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement