Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

"module://matplotlib_pyodide.wasm_backend" should auto clear the old pictures instead of generate new pictures #49

Open
yu0A opened this issue Jan 29, 2024 · 4 comments
Labels
bug Something isn't working

Comments

@yu0A
Copy link
Contributor

yu0A commented Jan 29, 2024

🐛 Bug

When use "module://matplotlib_pyodide.wasm_backend" to output pictures, each time it appends new divs and let the height of the page changes. That's unacceptable for admin apps.

To Reproduce

Clone this repo

  • deploy and run the code
  • go to the page http://localhost:9000/#/matplotlib
  • click the northwest button "执行" >= 2 times and you will see the page become longer and longer

Expected behavior

the constant amount of picture output

Environment

  • Pyodide Version:0.24.1
  • Browser version:Chrome 120.0.6099.227
  • Any other relevant information:

Additional context

@yu0A yu0A added the bug Something isn't working label Jan 29, 2024
@hoodmane hoodmane transferred this issue from pyodide/pyodide Jan 29, 2024
@ryanking13
Copy link
Member

Thanks for opening the issue. There is currently no maintainer actively managing matplotlib-pyodide, so it would be great if you could contribute to the issues you see.

@yu0A
Copy link
Contributor Author

yu0A commented Feb 1, 2024

Thanks for opening the issue. There is currently no maintainer actively managing matplotlib-pyodide, so it would be great if you could contribute to the issues you see.

I'm glad to maintain this repo. BTW are there any FAQs to debug emscripten whls like this?

@hoodmane
Copy link
Member

hoodmane commented Feb 1, 2024

BTW are there any FAQs to debug emscripten whls like this?

No, and it's a bit inconvenient but we are happy to provide suggestions / help if you get stuck. It's easier for wheels the work in node, but matplolib_pyodide is browser only.

I think the best thing is to unpack the wheel into some folder:

tmp-site/unpacked_wheel_pkg1
tmp-site/unpacked_wheel_pkg2
...

then do:

dirHandle = await showDirectoryPicker();
const nativefs = await pyodide.mountNativeFS("/mount_dir", dirHandle);
pyodide.pyimport("sys").path.insert(0, "/mount_dir")

and pick the tmp-site directory. Then you should be able to use the files on disk.
https://pyodide.org/en/stable/usage/file-system.html#experimental-using-the-native-file-system-in-the-browser

@yu0A
Copy link
Contributor Author

yu0A commented Feb 20, 2024

I successfully overload the destroy() function, and matplotlib does generate picture from "Figure 1".
chrome_yuYizqo78e

But a new bug is, pyodide cannot call div.removeChild() method successfully.

yu0A pushed a commit to yu0A/matplotlib-pyodide_20240201 that referenced this issue Mar 1, 2024
ryanking13 pushed a commit that referenced this issue Mar 7, 2024
…ose() method to delete previous divs (#55)

* fix bug #49

* add test for #55

* update the CHANGELOG.md

* add tests for #55

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

---------

Co-authored-by: yuhongbo <[email protected]>
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants