|
| 1 | +--- |
| 2 | +title: Runtime Versions |
| 3 | +jupyter: python3 |
| 4 | +--- |
| 5 | + |
| 6 | +```{python} |
| 7 | +import polars as pl |
| 8 | +import polars.selectors as cs |
| 9 | +import os |
| 10 | +from reactable import Reactable, Column, embed_css |
| 11 | +
|
| 12 | +if os.getenv("RSTUDIO_PRODUCT") != "CONNECT": |
| 13 | + from dotenv import load_dotenv |
| 14 | + load_dotenv() |
| 15 | +
|
| 16 | +from posit import connect |
| 17 | +client = connect.Client() |
| 18 | +
|
| 19 | +content = client.content.find() |
| 20 | +embed_css() |
| 21 | +``` |
| 22 | + |
| 23 | + |
| 24 | +## Python |
| 25 | + |
| 26 | +```{python} |
| 27 | +python_content = ( |
| 28 | + pl.DataFrame(content, infer_schema_length=None) |
| 29 | + .filter(pl.col("py_version").is_not_null()) |
| 30 | + .with_columns( |
| 31 | + pl.col("py_version") |
| 32 | + .str.split_exact(".", 3) |
| 33 | + .alias("split_version") |
| 34 | + ) |
| 35 | + .with_columns([ |
| 36 | + pl.col("split_version").struct.field("field_0").cast(pl.Int64).alias("major"), |
| 37 | + pl.col("split_version").struct.field("field_1").cast(pl.Int64).alias("minor"), |
| 38 | + pl.col("split_version").struct.field("field_2").cast(pl.Int64).alias("patch") |
| 39 | + ]) |
| 40 | +) |
| 41 | +
|
| 42 | +py_version_dfs = list(g for k, g in python_content.group_by("py_version")) |
| 43 | +py_summary_df = ( |
| 44 | + python_content |
| 45 | + .group_by(["py_version", "major", "minor", "patch"]) |
| 46 | + .agg(n=pl.len()) |
| 47 | + .sort(["major", "minor", "patch"]) |
| 48 | + .select(pl.col(["py_version", "n"]))) |
| 49 | +
|
| 50 | +Reactable( |
| 51 | + py_summary_df, |
| 52 | + default_sorted=["major"], |
| 53 | + details=Column( |
| 54 | + details=lambda ri: Reactable(py_version_dfs[ri.row_index]).to_widget(), |
| 55 | + ), |
| 56 | +) |
| 57 | +``` |
| 58 | + |
| 59 | +## R |
| 60 | + |
| 61 | +```{python} |
| 62 | +r_content = ( |
| 63 | + pl.DataFrame(content, infer_schema_length=None) |
| 64 | + .filter(pl.col("r_version").is_not_null()) |
| 65 | +) |
| 66 | +
|
| 67 | +r_version_dfs = list(g for k, g in r_content.group_by("py_version")) |
| 68 | +r_summary_df = r_content.group_by("py_version").agg(n=pl.count()) |
| 69 | +
|
| 70 | +Reactable( |
| 71 | + r_summary_df, |
| 72 | + details=Column( |
| 73 | + details=lambda ri: Reactable(r_version_dfs[ri.row_index]).to_widget(), |
| 74 | + ), |
| 75 | +) |
| 76 | +``` |
0 commit comments