Skip to content

Kivy Big Data on PC and Android

GitHub Repository

AI Transcript provided by KivyWhisper

So hello, this is a quick video. Basically what this is is a response to this Kivy post, which is, could Kivy work on my project for displaying data? I'm considering using Kivy for a data display app that runs on the tablet. It involves a bunch of sensor boxes that report back numerical data. Would Kivy be able to handle something like that? Each square in the grid can be tapped to change parameters for that square. The data is refreshed every second.

As you can see, this app by ElliotDG does it, this app by me does it. I forgot about the whole tapping and then making a pop-up, but that's fine. It's not that hard. You just on release or on press do a pop-up and then you update everything. So with that, I'm just going to go over how I solved it and then a couple of things that I did, what makes my solution a bit different from Elliot's. And then, yeah, let's go.

So it's a big data preview. It fulfills the calls on the Reddit. So basically I try to do a little bit more. I've totally forgotten about the whole press and then you get a pop-up, but that's fine. Anyways, as you can see here, there's something pretty interesting up here. If you see this, this is actually a Matplotlib data graph and people are saying you can update Kivy. It's so slow. OK, look at this. This is 50,000, five zero, zero, zero, zero data points on Matplotlib refreshed every second, along with the 240 something button text, along with the 240 button text inputs.

So Kivy is pretty good. Like I don't think anything spooky is going on. You can totally do a data display, something, especially on a tablet. And I'll show you because later on I'll put this app, the one I have, on my phone, my Android phone. So there's that. So yeah, it works. All the data is displaying correctly. And then let's just go over bonus features, advantages, and I'll just admit, you know, it's a bit hard to get an iOS. So let's do this. So bonus feature, I'm plotting every second 50,000 points with the Matplotlib widget by MP007. This is the link here. You can see it. And then I'm also updating all 240 buttons. And I can get on my Android phone. And then first I'll show because I'm using Kivy Reloader, this actually, if I go here, I press Ctrl S, it will reload the application. As you can see here, it has been reloaded. So that's something neat.

And then I will tell you this, getting on Android is really easy because like I've done it like several times now. But going iOS is going to be hard, not because it's hard, but because not a lot of people are doing it. So if your tablet is like iOS, maybe think about it. But I don't think it would be too spooky. There's already Matplotlib. There's already Matplotlib recipes. And it's not that hard to make a recipe for iOS. So there's that. And then I will admit Apple iOS tablet. Oh, I'm sorry. I admit Apple iOS tablets might be a challenge, but I got it working on my Android. So a couple advantages.

So one of the reasons why people think that Kivy is so laggy is because they put blocking code in their Kivy loop, right? There's a couple of solutions for this. The first solution is using Kivy in a Trio application, right? Which is what Kivy Reloader is doing. So here I'm going to say, Kivy Reloader uses Trio, which means that the Kivy app is already in async mode. And it's harder to lag it out even when doing intense computations. So that's one. You can use Trio.

Or number two is that you can use multiprocessing and put all of your CPU intensive code on and then just use a shared data type and then send from your subprocess to your main process. And the only thing that will lag you is your CPU speed. How fast does your CPU read? And I will tell you, it will... If you have like an... I will tell you, CPUs read data very, very, very fast, especially something basic like bytes. And then once you use that multiprocessing technique, you'll just clock out your CPU 100%. You will just ask for more. You'll max out your machine. Your machine literally cannot do more. So that's another thing with the multiprocessing technique. But nobody ever has to do that. That's only for machine learning applications. Also when you... Only for machine learning applications.

But most of the time, people are just async awaiting some sort of data from the internet and then they have to wait like five seconds for their five megabytes of data to be streamed through their Wi-Fi. That's totally easy. With Kivy Trio, you can just async await. Or even with a Kivy URL request, you can do it as well. So that's just a quick note on Kivy being slow, quote unquote. And then Kivy Reloader here makes it easy to get Android. And then again, Matplotlib is in the top half.

You can see that it uses NumPy, aka the hard computational stuff is done in C. And then the data here is also updated from the SamplerBox class. So I actually checked Elliot's class. These data widgets are just randomly updated from the data. And that's not right. And I'll tell you why that's not right. Because the way the data works is that you're going to have to find the one-to-one correspondence between your data set and the widgets. So for here, since I'm using... Oh, okay, close it. So here, since I'm using a grid layout, the problem is that Kivy goes left to right, top to bottom. And then some data, the data set was going top to bottom, left to right.

So that's another thing where you have to figure out how to finesse the data in order to read it properly. And then making this one-to-one connection is kind of annoying, but it doesn't mean it's impossible. It just means it's manual work. So there's one thing that I just noticed from Elliot's example that he didn't use the Sampler class in order to generate the data, which is what I did here. And then not only do I do it here, I do it for every second. So there's another cheat, which is that you could pre-generate the data and just load it. I don't even do that.

I just, every second I generate all the data, I generate the 50,000 points and the 240 points here, and then I update. So I didn't even need to pre-generate the data and just read. So there's not really a problem there. And then yeah, so for my example, the data is updated from the SamplerBox class. So that's it.

Quick note, oh, and I'm going to get on Android real quick. Let me just give you reloader run, then compile debug. And then let me get on my phone and unlock it. One second. Okay. And it took a while to push because it's kind of big, but. Let's see it. Okay, let's open. Screen copy. Hello. I've seen this before. Screen copy takes an infinite amount of time. New devices. Okay, it's here. Where are we? Arrange. seventh and the hold on Maybe I was connected on this terminal.

Okay, and as you can see, it's on my Android phone. I guess I'll tell you the one thing I can see already is, by the way, I use my fingers to touch it, but is, you know, my phone's too small. I can't really see these numbers. But as you can see, all the 240 widgets are working and then I'm creating 50,000 data points on it. Or map plot lib and it updates every second and it's not laggy as I can see. All right. Well, anyways, this has been Kivy School. Thank you for watching.

Article Error Reporting

Message @BadMetrics on the Kivy Discord.