Refine the pandas Dataframe with a filter on a JavaScript-enabled website

I recently inherited a large software project using Python/Flask on the backend and HTML/Javascript on the frontend. I'm now looking to add some interactivity to one of the websites. I have successfully passed a dataframe to the webpage and can display its content. I have implemented filters as buttons to switch between different views, with the ability to access filter values within the webpage itself. How can I pass these new values to the dataframe for filtering without needing to fully reload the page? It's worth noting that I use template.render() instead of render_templates() due to the absence of a templates folder in the project, making it too cumbersome to make this change. Here is the relevant Python code:

@app.route('/tagging/OverviewPerDoc.html')
def analysis():
    x = <function that returns a Pandas dataframe>()
    tempid = globalxmlid
    datatuple = [x, tempid]
    filetoopen = os.path.join(os.getcwd(), config.filepaths.overviewperdoc)

    with open(filetoopen) as fi:
        template = Template(fi.read())
    return template.render(data=datatuple)

This is the website aspect:

<body>
(...)
<button id="magicbutton" class="btn btn-primary my-group-button" type="submit" style="margin-right:5px;" value="Show">Show</button>
(...)
{% block content %}
(...)
<h1 align="center">{{data[0][data[0]['identifier'] == data[1]]['Name'].iloc[0]}}</h1>
(...)
<div class="container">
                        <table>
                      <tr>
                        <th></th>
(...)
                      <tr>
                        <td>Value</td>
                        <td>{{data[0][data[0]['identifier'] == data[1]]['Value'].iloc[0]}} {{data[0][data[0]['identifier'] == data[1]]['currency'].iloc[0]}}</td>
                        <td>100%</td>
                      </tr>
  (...) 

When clicking on my test button, I can print its value to the console.

<script>
    function magicfunction()
    {
        var test = savethecurrentxml;
        console.log(test);
}
</script>

Everything is functioning correctly, but I'm looking to modify it to something like:

data[0][data[0]['identifier'] == test]['Name'].iloc[0]

How can I go about accomplishing this?

Answer №1

To enhance your website performance, consider setting up a dedicated API endpoint to retrieve specific data from your filtered dataframe. By having JavaScript make a request to this endpoint, you can dynamically update your page content based on the retrieved response.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Ways to reduce the width of a flex box

I am facing an issue with my main container where I have two items placed on the same line. Item 1 is an image linked to a URL and it should be positioned at the far left of the container. On the other hand, item 2 contains a font awesome icon that needs t ...

An unexpected type error occurred: Unable to read the undefined property 'map' when utilizing Highcharts

I am currently working on developing highcharts using data from Firebase. I came across a helpful example here: However, when I try to integrate it into my application, I encounter the following error: firebase.js:43 Uncaught TypeError: Cannot read pr ...

Accessing the path to an imported file in Node.js

Currently, I am working on a parser and encountering imports such as ../modules/greeting.js. Additionally, I have an absolute path to the file from where I performed the import: C:\Desktop\Folder\src\scripts\main.js. I am seeking ...

Increase the bottom padding or add some extra space to the Bootstrap form or page

I am currently working on enhancing a Bootstrap Form that includes reset/submit buttons positioned at the bottom. A common issue is when iPhone users attempt to click the Submit button, which initially displays Safari icons before requiring an extra tap to ...

What steps should I follow to have my edit form component extract values from HTML in Angular?

I created a detailed listing page that includes a picture URL, title, phone number, description, and price. When the user clicks on the Edit button, it redirects them to a page with input forms for each of these fields. The form automatically populates the ...

The layout causes issues with responsiveness on the Flask app page

I'm currently in the process of developing a web application and I've implemented a navbar.html file as the layout for each page using the following code: eachpage.html : {% extends 'navbar.html' %} {% block body %} <div class=" ...

Dynamically populate 7 select boxes with options using JQuery

I have a webpage that includes 14 different dropdown menus, one for each day of the week (Monday to Sunday). Each day has two dropdowns: one for opening time and one for closing time. I used jQuery to populate all 14 dropdowns with a pre-defined list of ho ...

Upon executing the `npm start` command, the application experiences a crash

When I tried following the steps of the Angular quickstart guide, I encountered some errors after running "npm start". Here are the errors displayed: node_modules/@angular/common/src/directives/ng_class.d.ts(46,34): error TS2304: Cannot find name 'Se ...

The post() method in Express JS is functioning flawlessly in Firebase cloud function after deployment, however, it seems to encounter issues when running on a

https://i.stack.imgur.com/bIbOD.pngI am facing an issue with my Express JS application. Despite having both post() and get() requests, the post() request is not working on my local machine. It keeps throwing a 404 error with the message "Cannot POST / ...

How do I retrieve the class of an element nested within another element using jQuery?

If we consider a scenario where there is a table named unitTables with various rows, each containing the selected class that we want to retrieve for a variable. This specific table is just one of many similar tables on the webpage. Since other tables also ...

Encountering [Object Object] within an angular2 app

https://i.stack.imgur.com/iceKH.pngI recently created an angular2 application using ngrx/effects for handling http calls. My reference point was an application on GitHub. However, I am facing an issue where the response from the HTTP call is not displaying ...

What are the steps to redirect from a nested route back to the top route using Node.js with Express?

Is there a way to redirect from a nested route to a top route in Express.js? In the following code snippet, how can we make the callback for the route /toproute/nested redirect to /profile instead of /toproute/profile? // app.js const express = require(& ...

Learning to extract information from elements within components in a flexbox using Angular

Is there a way to access the element width of child components within a parent component that utilizes flex box? I am hoping to determine if the list is overflowed so I can adjust the visibility of elements accordingly. If an overflow occurs, I would like ...

Cricket score update features on the client side

Looking for assistance with client-side code development! I am currently working on an Android application using Ionic that involves live cricket scores. I have purchased a cricket API and understand how to connect to it using Node.js on the server side. ...

How to retrieve controller property from a different Class in AngularJS

While working with AngularJS today, I came across an issue that I need help resolving. Here is the code snippet in question: app.controller("SomeController", function(){ this.foo = true this.changeFoo = function(bool){ ...

Animating a dotted border path in SVG for a progress bar effect

I am attempting to create an animation for a dotted SVG circle that resembles a progress bar, where it fills itself over a duration of 3 seconds. However, I am facing difficulties in achieving this effect with the dotted border. The current code I have doe ...

Utilize Mapbox-GL.JS to animate several points along designated routes

I'm encountering issues with the following example: Animate a point along a route My goal is to add another point and routes in the same map container. Here's what I've tried so far: mapboxgl.accessToken = 'pk.eyJ1IjoicGFwYWJ1Y2t ...

Leveraging the power of jQuery to capture and recycle a dynamically generated date

Using a jQuery plugin, a list of dates is generated. Implementing moment.js works perfectly fine as shown in this fiddle (http://jsfiddle.net/UJ9z4/). However, when attempting to apply it to the live file with the plugin running, an undefined error is enc ...

Guide on converting the names of weekdays and months in a Django calendar into different languages

I am looking to change the language of the days and months displayed in a Django calendar from English to Polish. I have tried adjusting the settings and using LocalHTMLCalendar without success. Below is my utlis.py file: class Calendar(LocaleHTMLCalendar ...

Transform the componentDidUpdate method that uses prevProps into a custom hook integrated with Redux

Trying to convert a life cycle method into a hook is not working as expected. When the component mounted, if the user ID exists in local storage, the user is connected and their name is displayed in the navbar. If they disconnect and reconnect, their name ...