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

work with Polars ? #42

Open
yingweixiang opened this issue Jan 12, 2025 · 9 comments
Open

work with Polars ? #42

yingweixiang opened this issue Jan 12, 2025 · 9 comments

Comments

@yingweixiang
Copy link

Thank you for your beautiful charts!

Does leptos-chartistry support Polars? I mean using Polars to read .csv file, then do data cleaning & transforming, then use polars_rows_iter to create a Vec, then create a Signal<Vec> to load data and create charts.

I used R/shiny in the past, but it would be cool to do the same thing in rust.

Thanks,
Yingwei

@feral-dot-io
Copy link
Owner

Hello Yingwei,

Yes, what you've described should work as the glue here is getting the data into Leptos. Once you have the Signal<Vec<f64>> (the f64 is important), the charts can be built like any other.

I'm not familiar with Polars but now I'm thinking maybe I should be.

@yingweixiang
Copy link
Author

Thanks, I'll try to play with that Signal<Vec>. Yingwei

@yingweixiang
Copy link
Author

one more question:
it seems that the x values should be f64, it can not be categorical data, like strings.
I changed the x of sample Mydata to String type, it won't work, saying String type doesn't implement trait Tick.

so, all x and y values should all be f64 type, right ?

Thanks,
Yingwei

@feral-dot-io
Copy link
Owner

Yes that's right. The Tick trait currently only implements for f64 and Chrono's DateTime. You can see all the implementations here: https://docs.rs/leptos-chartistry/0.2.1/leptos_chartistry/trait.Tick.html#foreign-impls

It's a sealed trait and categorical / strings would need a whole bunch of work not yet done.

@yingweixiang
Copy link
Author

I can run your sample SSR app in my local host. However, after "cargo add polars", (polars = "0.45.1" in Cargo.toml), I can't run your sample SSR app. Then I tried a simple leptos sample app from the leptos book. After adding polars, it didn't work either.
I only add polars = "0.45.1" in Cargo.toml, nothing else.

there are 5 errors, all related to crossterm-0.28.1.

I guess that I need to ask questions in Leptos forum.

@feral-dot-io
Copy link
Owner

Can you share the full set of errors?

@yingweixiang
Copy link
Author

Please see info below.

Compiling psm v0.1.24
Compiling stacker v0.1.17
Compiling bytemuck v1.21.0
Compiling polars-error v0.45.1
Compiling chrono-tz v0.10.0
Compiling memmap2 v0.9.5
Compiling hydration_context v0.2.1
Compiling strum_macros v0.26.4
Compiling target-features v0.1.6
Compiling polars-schema v0.45.1
Compiling multiversion-macros v0.7.4
Compiling serde_json v1.0.127
warning: psm@0.1.24: Compiler family detection failed due to error: ToolNotFound: Failed to find tool. Is clang installed? (see https://docs.rs/cc/latest/cc/#compile-time-requirements for help)
warning: psm@0.1.24: Compiler family detection failed due to error: ToolNotFound: Failed to find tool. Is clang installed? (see https://docs.rs/cc/latest/cc/#compile-time-requirements for help)
error: failed to run custom build command for psm v0.1.24

Caused by:
process didn't exit successfully: D:\webleptos\chartistry_ssr\target\front\debug\build\psm-29dd8ed71a3098e5\build-script-build (exit code: 1)
--- stdout
OPT_LEVEL = Some(0)
OUT_DIR = Some(D:\webleptos\chartistry_ssr\target\front\wasm32-unknown-unknown\debug\build\psm-05f07a1d9aed3cb0\out)
TARGET = Some(wasm32-unknown-unknown)
HOST = Some(x86_64-pc-windows-msvc)
cargo:rerun-if-env-changed=CC_wasm32-unknown-unknown
CC_wasm32-unknown-unknown = None
cargo:rerun-if-env-changed=CC_wasm32_unknown_unknown
CC_wasm32_unknown_unknown = None
cargo:rerun-if-env-changed=TARGET_CC
TARGET_CC = None
cargo:rerun-if-env-changed=CC
CC = None
cargo:rerun-if-env-changed=CC_ENABLE_DEBUG_OUTPUT
cargo:warning=Compiler family detection failed due to error: ToolNotFound: Failed to find tool. Is clang installed? (see https://docs.rs/cc/latest/cc/#compile-time-requirements for help)
RUSTC_WRAPPER = None
cargo:rerun-if-env-changed=CRATE_CC_NO_DEFAULTS
CRATE_CC_NO_DEFAULTS = None
DEBUG = Some(true)
cargo:rerun-if-env-changed=CFLAGS_wasm32-unknown-unknown
CFLAGS_wasm32-unknown-unknown = None
cargo:rerun-if-env-changed=CFLAGS_wasm32_unknown_unknown
CFLAGS_wasm32_unknown_unknown = None
cargo:rerun-if-env-changed=TARGET_CFLAGS
TARGET_CFLAGS = None
cargo:rerun-if-env-changed=CFLAGS
CFLAGS = None
CARGO_ENCODED_RUSTFLAGS = Some()
cargo:rustc-check-cfg=cfg(switchable_stack,asm,link_asm)
cargo:rustc-cfg=asm
cargo:rustc-cfg=link_asm
cargo:rustc-cfg=switchable_stack
cargo:rerun-if-env-changed=AR_wasm32-unknown-unknown
AR_wasm32-unknown-unknown = None
cargo:rerun-if-env-changed=AR_wasm32_unknown_unknown
AR_wasm32_unknown_unknown = None
cargo:rerun-if-env-changed=TARGET_AR
TARGET_AR = None
cargo:rerun-if-env-changed=AR
AR = None
cargo:warning=Compiler family detection failed due to error: ToolNotFound: Failed to find tool. Is clang installed? (see https://docs.rs/cc/latest/cc/#compile-time-requirements for help)
cargo:rerun-if-env-changed=CROSS_COMPILE
CROSS_COMPILE = None
RUSTC_LINKER = None
cargo:rerun-if-env-changed=ARFLAGS_wasm32-unknown-unknown
ARFLAGS_wasm32-unknown-unknown = None
cargo:rerun-if-env-changed=ARFLAGS_wasm32_unknown_unknown
ARFLAGS_wasm32_unknown_unknown = None
cargo:rerun-if-env-changed=TARGET_ARFLAGS
TARGET_ARFLAGS = None
cargo:rerun-if-env-changed=ARFLAGS
ARFLAGS = None

--- stderr

error occurred in cc-rs: Failed to find tool. Is ar installed? (see https://docs.rs/cc/latest/cc/#compile-time-requirements for help)

warning: build failed, waiting for other jobs to finish...

@yingweixiang
Copy link
Author

above info is when compiling leptos-chartistry SSR sample.

when compiling basic Leptos sample from leptos book, it says:

error[E0425]: cannot find function enable_raw_mode in module sys
--> C:\Users\yingw.cargo\registry\src\index.crates.io-6f17d22bba15001f\crossterm-0.28.1\src\terminal.rs:123:10
|
123 | sys::enable_raw_mode()
| ^^^^^^^^^^^^^^^ not found in sys
|
note: found an item that was configured out
--> C:\Users\yingw.cargo\registry\src\index.crates.io-6f17d22bba15001f\crossterm-0.28.1\src\terminal\sys.rs:8:23
|
8 | disable_raw_mode, enable_raw_mode, is_raw_mode_enabled, size, window_size,
| ^^^^^^^^^^^^^^^
note: the item is gated here
--> C:\Users\yingw.cargo\registry\src\index.crates.io-6f17d22bba15001f\crossterm-0.28.1\src\terminal\sys.rs:6:1
|
6 | #[cfg(unix)]
| ^^^^^^^^^^^^
note: found an item that was configured out
--> C:\Users\yingw.cargo\registry\src\index.crates.io-6f17d22bba15001f\crossterm-0.28.1\src\terminal\sys.rs:17:30
|
17 | clear, disable_raw_mode, enable_raw_mode, is_raw_mode_enabled, scroll_down, scroll_up,
| ^^^^^^^^^^^^^^^
note: the item is gated here
--> C:\Users\yingw.cargo\registry\src\index.crates.io-6f17d22bba15001f\crossterm-0.28.1\src\terminal\sys.rs:15:1
|
15 | #[cfg(windows)]
| ^^^^^^^^^^^^^^^

error[E0425]: cannot find function disable_raw_mode in module sys
--> C:\Users\yingw.cargo\registry\src\index.crates.io-6f17d22bba15001f\crossterm-0.28.1\src\terminal.rs:130:10
|
130 | sys::disable_raw_mode()
| ^^^^^^^^^^^^^^^^ not found in sys
|
note: found an item that was configured out
--> C:\Users\yingw.cargo\registry\src\index.crates.io-6f17d22bba15001f\crossterm-0.28.1\src\terminal\sys.rs:8:5
|
8 | disable_raw_mode, enable_raw_mode, is_raw_mode_enabled, size, window_size,
| ^^^^^^^^^^^^^^^^
note: the item is gated here
--> C:\Users\yingw.cargo\registry\src\index.crates.io-6f17d22bba15001f\crossterm-0.28.1\src\terminal\sys.rs:6:1
|
6 | #[cfg(unix)]
| ^^^^^^^^^^^^
note: found an item that was configured out
--> C:\Users\yingw.cargo\registry\src\index.crates.io-6f17d22bba15001f\crossterm-0.28.1\src\terminal\sys.rs:17:12
|
17 | clear, disable_raw_mode, enable_raw_mode, is_raw_mode_enabled, scroll_down, scroll_up,
| ^^^^^^^^^^^^^^^^
note: the item is gated here
--> C:\Users\yingw.cargo\registry\src\index.crates.io-6f17d22bba15001f\crossterm-0.28.1\src\terminal\sys.rs:15:1
|
15 | #[cfg(windows)]
| ^^^^^^^^^^^^^^^

error[E0425]: cannot find function size in module sys
--> C:\Users\yingw.cargo\registry\src\index.crates.io-6f17d22bba15001f\crossterm-0.28.1\src\terminal.rs:137:10
|
137 | sys::size()
| ^^^^ not found in sys
|
note: found an item that was configured out
--> C:\Users\yingw.cargo\registry\src\index.crates.io-6f17d22bba15001f\crossterm-0.28.1\src\terminal\sys.rs:8:61
|
8 | disable_raw_mode, enable_raw_mode, is_raw_mode_enabled, size, window_size,
| ^^^^
note: the item is gated here
--> C:\Users\yingw.cargo\registry\src\index.crates.io-6f17d22bba15001f\crossterm-0.28.1\src\terminal\sys.rs:6:1
|
6 | #[cfg(unix)]
| ^^^^^^^^^^^^
note: found an item that was configured out
--> C:\Users\yingw.cargo\registry\src\index.crates.io-6f17d22bba15001f\crossterm-0.28.1\src\terminal\sys.rs:18:33
|
18 | set_size, set_window_title, size, window_size,
| ^^^^
note: the item is gated here
--> C:\Users\yingw.cargo\registry\src\index.crates.io-6f17d22bba15001f\crossterm-0.28.1\src\terminal\sys.rs:15:1
|
15 | #[cfg(windows)]
| ^^^^^^^^^^^^^^^

error[E0425]: cannot find function window_size in module sys
--> C:\Users\yingw.cargo\registry\src\index.crates.io-6f17d22bba15001f\crossterm-0.28.1\src\terminal.rs:154:10
|
154 | sys::window_size()
| ^^^^^^^^^^^ not found in sys
|
note: found an item that was configured out
--> C:\Users\yingw.cargo\registry\src\index.crates.io-6f17d22bba15001f\crossterm-0.28.1\src\terminal\sys.rs:8:67
|
8 | disable_raw_mode, enable_raw_mode, is_raw_mode_enabled, size, window_size,
| ^^^^^^^^^^^
note: the item is gated here
--> C:\Users\yingw.cargo\registry\src\index.crates.io-6f17d22bba15001f\crossterm-0.28.1\src\terminal\sys.rs:6:1
|
6 | #[cfg(unix)]
| ^^^^^^^^^^^^
note: found an item that was configured out
--> C:\Users\yingw.cargo\registry\src\index.crates.io-6f17d22bba15001f\crossterm-0.28.1\src\terminal\sys.rs:18:39
|
18 | set_size, set_window_title, size, window_size,
| ^^^^^^^^^^^
note: the item is gated here
--> C:\Users\yingw.cargo\registry\src\index.crates.io-6f17d22bba15001f\crossterm-0.28.1\src\terminal\sys.rs:15:1
|
15 | #[cfg(windows)]
| ^^^^^^^^^^^^^^^

Compiling psm v0.1.24
Compiling stacker v0.1.17
error[E0308]: mismatched types
--> C:\Users\yingw.cargo\registry\src\index.crates.io-6f17d22bba15001f\crossterm-0.28.1\src\terminal.rs:107:33
|
107 | pub fn is_raw_mode_enabled() -> io::Result {
| ------------------- ^^^^^^^^^^^^^^^^ expected Result<bool, Error>, found ()
| |
| implicitly returns () as its body has no tail or return expression
|
= note: expected enum Result<bool, std::io::Error>
found unit type ()

Compiling polars-ops v0.45.1
Some errors have detailed explanations: E0308, E0425.
For more information about an error, try rustc --explain E0308.
Compiling argminmax v0.6.2
error: could not compile crossterm (lib) due to 5 previous errors
warning: build failed, waiting for other jobs to finish...

@feral-dot-io
Copy link
Owner

Are you accidentally or unintentionally compiling Polars to wasm?

If so, try compiling it only when building SSR. See in the SSR Cargo.toml there are dependencies listed like tokio = { version = "1.42", features = [ "full" ], optional = true } The "optional = true" means they don't get compiled unless enabled by a feature. You can see it activated in the ssr feature:

The other thing to check would be that you have clang installed. If polars works in another project then it's probably set up correctly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants