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

[WIP] Apply simplifications for stlite #7877

Draft
wants to merge 1 commit into
base: develop
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
9 changes: 8 additions & 1 deletion frontend/app/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -874,7 +874,14 @@ export class App extends PureComponent<Props, State> {
const pagePath = viewingMainPage ? "" : newPageName
const pageUrl = `${basePathPrefix}/${pagePath}${qs}`

window.history.pushState({}, "", pageUrl)
// Remove the trailing slash unless it results in an empty string to avoid undesirable path overrides
// such as "/test.html" -> "/test.html/". These are problematic for uses with stlite.
const trimmedPageUrl =
pageUrl.endsWith("/") && pageUrl !== "/"
? pageUrl.slice(0, -1)
: pageUrl

window.history.pushState({}, "", trimmedPageUrl)
}
}

Expand Down
3 changes: 2 additions & 1 deletion frontend/lib/src/components/elements/ImageList/ImageList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ export function ImageList({
height,
endpoints,
}: ImageListProps): ReactElement {
const images = element.imgs
// The width field in the proto sets the image width, but has special
// cases for -1, -2, and -3.
let containerWidth: number | undefined
Expand Down Expand Up @@ -91,7 +92,7 @@ export function ImageList({

return (
<StyledImageList style={{ width }}>
{element.imgs.map((iimage: IImage, idx: number): ReactElement => {
{images.map((iimage: IImage, idx: number): ReactElement => {
const image = iimage as ImageProto
return (
<StyledImageContainer key={idx} data-testid="stImage">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,12 @@ export function toSafeArray(data: any): any[] {
return [data]
}

if (data instanceof Uint8Array) {
// Uint8Array might be used to represent string (json) data
// which needs to be decoded to a string here.
data = new TextDecoder("utf-8").decode(data)
}

if (typeof data === "string") {
if (data === "") {
// Empty string
Expand Down
4 changes: 3 additions & 1 deletion frontend/lib/src/dataframes/Quiver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1002,7 +1002,9 @@ but was expecting \`${JSON.stringify(expectedIndexTypes)}\`.
public static getTypeName(type: Type): IndexTypeName | string {
// For `PeriodType` and `IntervalType` types are kept in `numpy_type`,
// for the rest of the indexes in `pandas_type`.
return type.pandas_type === "object" ? type.numpy_type : type.pandas_type
const typeName =
type.pandas_type === "object" ? type.numpy_type : type.pandas_type
return typeName.toLowerCase().trim()
}

/** Takes the data and it's type and nicely formats it. */
Expand Down
11 changes: 8 additions & 3 deletions frontend/lib/src/util/UriUtil.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,14 @@ export function getWindowBaseUriParts(): BaseUriParts {
port = isHttps() ? 443 : 80
}

const basePath = window.location.pathname
.replace(FINAL_SLASH_RE, "")
.replace(INITIAL_SLASH_RE, "")
// "about:blank" is sometimes as href when Streamlit is running
// within an iframe with inline code, e.g. in the case of stlite.
const basePath =
window.location.href === "about:blank"
? ""
: window.location.pathname
.replace(FINAL_SLASH_RE, "")
.replace(INITIAL_SLASH_RE, "")

return { host, port, basePath }
}
Expand Down
4 changes: 2 additions & 2 deletions lib/streamlit/elements/lib/column_config_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -349,7 +349,7 @@ def _determine_data_kind(


def determine_dataframe_schema(
data_df: pd.DataFrame, arrow_schema: pa.Schema
data_df: pd.DataFrame, arrow_schema: Optional[pa.Schema]
) -> DataframeSchema:
"""Determine the schema of a dataframe.

Expand Down Expand Up @@ -378,7 +378,7 @@ def determine_dataframe_schema(
for i, column in enumerate(data_df.items()):
column_name, column_data = column
dataframe_schema[column_name] = _determine_data_kind(
column_data, arrow_schema.field(i)
column_data, arrow_schema.field(i) if arrow_schema else None
)
return dataframe_schema

Expand Down