I have seen a tutorial here Which is demonstrating the data analysis in the jupyter notebook cell, I am looking for the solution that how can i show the output of autoplotter which is python library in the django templates. Below is the code snippet of autoplotter which i have taken from its official website:
from autoplotter import run_app # Importing the autoplotter for GUI Based EDA
import pandas as pd # Importing Pandas to read csv
df = pd.read_csv("https://raw.githubusercontent.com/ersaurabhverma/autoplotter/master/Data/data.csv") # Reading data
run_app(df,mode = "inline", host="127.0.0.1", port=5000) # Calling the autoplotter.run_app in inline mode
run_app(df,mode = "external", host="127.0.0.1", port=5000) # Calling the autoplotter.run_app in external mode
I am looking for that what is the output format of this command
run_app (dataframe, host, port....)
how can I display its output in my django templates? so that a person could interact with his data through my launched website? Looking for any smart solution. Thank you
You can't run it under Django project because autoplotter uses Flask to serve the data and Flask can work only in the main thread of the main interpreter.
However, you can solve your problem using Docker. You will have a separate service that serves the autoplotter app and Django can have an iframe in HTML template that shows the content of the service.
UPD:
For the Docker - you can start with this guide. The only difference will be in your case is that app.py will contain only the call for a plotter:
if __name == '__main__':
run_app(df, mode="external", host="127.0.0.1", port=5000)
And requirements.txt with autoplotter
Related
I am tryining to read a parquet file from the azure data lake Gen1 from my company. Manually I can achieve this by running the following code
from azure.datalake.store import lib
from azure.datalake.store.core import AzureDLFileSystem
import pandas as pd
adlCreds = lib.auth(tenant_id='59...66',
resource = 'https://datalake.azure.net/')
adlsFileSystemClient = AzureDLFileSystem(adlCreds, store_name='...datacore')
f = adlsFileSystemClient.open('/qas/.../part-00000-366b8e91-5edd-4ce2-a70f-5fdd3e1a0fe5-c000.snappy.parquet', 'rb')
df= pd.read_parquet(f)
The only problem is that when I get to the adlCreds line I receive the following message:
To sign in, use a web browser to open the page https://microsoft.com/devicelogin and enter the code EH.....RT to authenticate.
Following this instructions the code works perfectly.
However what I would like to do is run a code similar to this in an azure app function. What I am struggling with is that I don't know how to do this authentication. Is there any way I can allow access to a certain file or folder in data lake for a particular resource? In this case the app function?
In one of the requirement, I need to integrate Google Map with Dash framework and on map click - retrieve lat , long and address (on map click event).
I was able to retrieve the same using google API and flask framework using java script which gives Lat ,Long and Address based on map click event and renders Google Map
Here is the python code used in flask framework :
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import json
from flask import Flask, render_template, request
app = Flask(__name__)
#app.route('/map', methods=['GET', 'POST'])
def map():
location = {}
if request.method == "POST":
location = request.get_json()
# latitude = location['latitude']
# longitude = location['longitude']
print(location);
return render_template('map.html')
if __name__ == '__main__':
app.run(debug = True) # run app
Any guidance how to achieve the same using Dash Framework would be really helpful. I can share JS Script Code as well if needed.
You could use Dash Leaflet for the map visualization. It supports arbitrary tile provides, i.e. also Google, as well as click events. You would need another library for the reverse geocoding though, one options is Googles API.
Disclaimer: I am the maintainer of Dash Leaflet.
I just started working with web tools and flask.I have a python script with 9 functions and I am trying to make a flask application. the main view of this application would do the same thing as my python script (in which some functions are intermediate meaning they do not produce the final output and 2 functions produce the final output). since for one route I have 9 functions, what do you suggest? shall I rename my original script as view.py and call it in the app.py (under the corresponding route) or there is better way?
Creating a separate file is always a better choice. It will make the code more readable and understandable.
Simply create a file and call the method in app.py like this.
from flask import Flask, jsonify
from views import your_method_name
# Initialize the app
app = Flask(__name__)
# Route (e.g. http://127.0.0.1:5000/my-url)
#app.route("/my-url", methods=['POST'])
def parse():
response = your_method_name() # call the method
return jsonify(response)
if __name__ == '__main__':
app.run()
So I'm creating a website and I was wondering if I could create a button / link to open a FILE, not another website, but a .py file. -Thanks
We have object tag in html. You create one button and an object. When u click on the button then you have to change the data attribute value of object tag.
It will work.
Use any lightweight python web framework like Flask.
Then use a script like this to run it on a website:
from flask import Flask
app = Flask(__name__)
#app.route("/")
def hello():
#do your things here
return "It works!"
if __name__ == "__main__":
app.run()
Then run the server :
python script. py
Now the server is running on port 5000
So when you visit (eg: http://rasp_pi_ip:5000/) the website, your script will run.
So I am using python flask to develop a web application that asks the user for data, analyse the data in the backend using BLAST and R, and outputs interactive HTML plots that are stored in a local location (Templates) and to be displayed to the user.
Everything up to R outputs runs smoothly. I have opened the HTML files and confirmed the R codes ran as expected and the produced graphs are interactive. However when I render these HTMLs through flask the browser returns a black page. Using send_file was also fruitless to display the plots. I have confirmed that the path to the Java scripts for the interactive plot are in the same folder.
Going through the developers tool console reads the following error:
htmlwidgets.js:1 Uncaught SyntaxError: Unexpected token <
jquery.min.js:1 Uncaught SyntaxError: Unexpected token <
datatables.js:1 Uncaught SyntaxError: Unexpected token <
jquery.dataTables.min.js:1 Uncaught SyntaxError: Unexpected token <
Can someone please advise on how to successfully get the interactive R HTML outputs to show in flask?
When you use send_file or send_from_directory you would also need to serve the JavaScript libraries needed for the plot, this might be the reason for the blank page.
The same is true for render_template but according to the error messages it seems more like that your JS libraries were also rendered as templates and some < or > character got added or removed.
Try the following snippet which works for me and perhaps gives you a good start.
A very simple R script to create a standalone HTML file with a Plotly plot. A file called test.html is created in the /tmp directory. All JavaScript libraries and CSS files are in /tmp/test_files.
library(plotly)
library(htmlwidgets)
myData <- data.frame(x=c(1,2,3), y=c(3,2,1))
local_path <- '/tmp/'
ply <- plot_ly(myData, x = ~x, y = ~y, type='scatter', mode='markers+line')
saveWidget(widget=ply, file=paste(local_path, "test.html", sep=""), selfcontained = FALSE)
A minimal Flask server snippet to serve the plot and the JavaScript libraries is below. Starting flask and going in the browsesr to http://localhost:5000/ would show the plot and provide all need libraries.
from flask import Flask
from flask import send_from_directory
app = Flask(__name__)
#app.route('/')
def plotly():
return send_from_directory('/tmp/', 'test.html')
#app.route('/test_files/<path:path>')
def send_js(path):
return send_from_directory('/tmp/test_files', path)