How to update a plotly graph with new data in Python? - python

I am using Chart Studio. How do I update my graph with new data, without losing previously uploaded data? I cannot upload everything all at once every time, because uploads are "limited to 524.288 KB". So I have to upload incrementally. Is this possible? By the way, fileopt='extend' does not work in the new version upgrade, but that is the type of functionality I am looking for.

I did not discover how to extend traces however I did find out how to get around the upload limit. The method involves generating charts on github pages which can be used to create iframes, without file size limits. This is an effective workaround for me. More information here: https://towardsdatascience.com/how-to-create-a-plotly-visualization-and-embed-it-on-websites-517c1a78568b

Related

How to create a static skeleton of a map using folium with over layers(markers) changing every hour which is hosted over a website using flask?

I am sorry if the question is confusing or doesn't make sense, this is my first project and I'll try to explain it to the best of my capabilities.
At first, I thought I would just be hosting a single map that I created using folium and inherited the template of the map into the website which is created with flask, therefore I didn't do any hardcoding in the main app.py file, however, it seemed really basic. So now using machine learning algorithms, I want to display different things over the map which makes some predictions for every hour of the day.
THE PROBLEM: It will take longer than expected to generate a new map every hour of the day (plus storing a new map so many times will be expensive in terms of storage).
MY SOLUTION: Have a skeleton map because the area that I will be making predictions on is localized, so have that area as the basic map and change the upper layers that will have the predictions displayed (basically heat map) every hour.
Is this a correct approach? Please recommend a right path to implement this. I am open to trying new things as long as it gets the job done. Would really appreciate any help regarding this. Thanks in advance
Folium does not support WebSockets if anything add new javascript to fetch data dynamically, but the best way would be to fetch data instead of rendering html everytime, it would help with the speed issue as well. Also, look into leaflets that would help too.
If you want to generate your map faster, you can use directly the Javascript library Leaflet to create the map (it is the library that is used to render the map with Folium). You need to send the data of your predictions from your backend in Flask to your front-end in Javascript with Leaflet in your HTML template (Jinja2).

Best way to read and write data on google colab?

I'm making an application that shows the correlation between your daily habits and your mood. Because python has so many of the components I need and I wan't this to be web based (also I'm not worried about the front end right now) I'm leaning towards using colab.
The problem is the session storage. I know how to work with pre-existing data but I'm totally unfamiliar with storing collected data with python. It's a light weight app and I'd like to use the panda's library to visualize the data.
The point is: I don't know how I should store the data that will be input on a daily basis on colab for future use. Of course, every time I run the colab, data collected will be cleared. What's the best way to store data from each use on colab? Can I create a csv file on my google drive and read / write to that file and if so what's the best method?
If colab seems like a bad option, I'll use javascript to collect the data & d3.js to visualize but I'd like to stick to colab if I can so I don't have to stand up my own webpage.
Since you want it to be web-based, you can use Heroku Student Plan with Github Education or PythonAnywhere. Because the colab session will stop after 12 hours and it is a headache to run it again.
In case, you still want to use Colab, one way is to save data into a file and keep it in Google Drive. In this case,
Saving of data can be automated. But you'll need to get access token for Google Drive every session. Check Example I/O notebook
Other methods are generally inconvenient

Import data from excel spreadsheet to django model

I'm building a website that'll have a django backend. I want to be able to serve the medical billing data from a database that django will have access to. However, all of the data we receive is in excel spreadsheets. So I've been looking for a way to get the data from a spreadsheet, and then import it into a django model. I know there are some different django packages that can do this, but I'm having a hard time understanding how to use these packages. On top of that I'm using python 3 for this project. I've used win32com for automation stuff in excel in the past. I could write a function that could grab the data from the spreadsheet. Though what I want figure out is how would I write the data to a django model? Any advice is appreciated.
Use http://www.python-excel.org/ and consider this process:
Make a view where user can upload the xls file.
Open the file with xlrd. xlrd.open_workbook(filename)
Extract, create dict to map the data you want to sync in db.
Use the models to add, update or delete the information.
If you follow the process, you can learn a lot of how loading and extracting works and how does it fits with the requirements. I recommend to you first do the step 2 and 3 in shell to get more quicker experiments and avoid to be uploading/testing/error with a django view.
Hope this kickoff base works for you.
Why don't you use django-import-export?
It's a widget that allows you to import excel files from admin section.
It's very easy to install, here you find the installation tutorial, and here an example.
Excel spreadsheets are saved as .csv files, and there are plenty of examples and explanations on how to work with them, such as here and here, online already.
In general, if you are having difficulty understanding documentation or packages, my advice would be to search for specific examples or see if whatever you are trying to do has already been done. Play with it to get a working understanding, and then modify it to fit your needs.

Generate dynamic plots with python

I am working on generating some plots using python, but I am generating these plots using matplotlib which is saved as images. If I create an html page as a report with these plots, they are static images. I cannot zoom in or roll over on the plot to see more detailed or specific information on a time series plot.
My question is how can I make these plots dynamic? Can someone suggest the best way to get started and move forward from there?
You should use some additional libraries to achive your goal.
For example, there some good Python web frameworks wich you can use:
CherryPy - allows you to simply write web-app with Python and you can import your plot there.
Plotly Python API - it would simply generate interactive plot, but store it at Plotly platform, but they provide embeded-code option, so you can use it on your site.
I would suggest Plotly, because it is much simpler, but it depends on your needs.
You will definitely want to do it using javascript. It's by far your best option when it comes to quickly make interactive graphs that you can present to a lot of users. Any of these js libraries will do a great job.
You will then want python to provide the data. Depending on the js library you are using, you might be able to parse data from .json, .csv, etc...
If you don't need the data that makes up your plots to change (with user input, for example), then generating and saving flat files with python and having javascript parsing them from some directory might be just enough.
Otherwise, you want to take a look at a python web framework and use one as backend to serve the plots data by request (in that case .json is probably the right format).
Frameworks like Flask, CherryPy, Pyramid or even web2py might be the easier ones to start with.

how do I use the facebook api to modify a video title or description?

How can I update the title/description of a previously updated video? I am using python and pyfacebook... but any starting point would be fine and I can write it in python.
I don't think it's possible to edit a Video object at all with the Graph API at the moment. You can't create objects through the API, therefore I don't think you can edit or modify existing ones either.

Categories

Resources