Skip to content

Conversation

@CFrez
Copy link
Contributor

@CFrez CFrez commented Feb 18, 2021

Based off of #2716. Minor adjustments to padding, gap and flex/flex-basis to better align columns between different rows.

Gap affects alignment since "expands" the content box and is affected by how many columns are in a row. Padding (with border-box sizing) does not affect row no matter how many columns.

Currently, both padding-left and gaps are used.

This change alters it to use just padding-left for regular screen sizes, and then only gap when smaller.

The removal of padding-left for smaller sizes was driven by that a column maintained its left padding even after the row was wrapped and it no longer needed it. This caused misalignment along the left size of the inputs. Gap automatically accommodates for the columns at the exterior.

To adjust spacing since only gap or padding is used now, I increased the spacing from theme.spacing.sm to theme.spacing.md.

The other change was to shift the flex-basis (controlled by flex) parameter to use percentages instead of just numbers for the row. This defines the initial width of each column to be based off the percentage of the container width. Using just the weight numbers directly controls how the "extra" space outside of the content gets divided.

A good image from the w3 spec:

Screen Shot 2021-02-17 at 8 10 59 PM

Results image (also provided in issue):

Screen Shot 2021-02-17 at 6 48 20 PM

CFrez and others added 23 commits February 12, 2021 15:11
* remove extra padding

* remove snapshot completely

* add snapshot back in

* remove snapshots

* remove rest of snapshots

* add snapshots back in
* autofocus clear cache button

* add test

* update test

* fix lint
Point our `component-template` submodule to the latest commit in that repo.

(Among other things, this will de-dupe a bunch of the `component-lib` code that used to live in `component-template` before being pulled into its own npm package.)
* Close streamlit#2699

* Override Thumb subcomponent completely

* Fixed linting errors

Co-authored-by: Ken McGrady <[email protected]>
)

* Copy to shared and cleanup

* Cleanup

* remove comment
Adds a new config option, `"client.showTracebacks"`. By default, it's `True`.

If the option is set to `False`, then uncaught exceptions in a Streamlit app will result in a generic "Something went wrong!" warning in the browser, rather than the exception and its traceback

This logic happens in the `error_util.handle_uncaught_app_exception` function, rather than directly within ScriptRunner.

`scriptrunner_test`, `caching_test`, and `streamlit_test` have new tests that verify the right thing happens when exceptions are thrown in different circumstances with this config option turned on and off.

Closes streamlit#1032
* remove nonexistent elements from widget states

* fix typo

* add test
* save changes

* remove redundant change

* fix tests

* fix quotes

* add tests and other fixes

* fix lint

* update protobufs and tests

* add e2e test

* fix quotes

* update test
@CFrez CFrez requested a review from a team February 18, 2021 02:18
@CFrez
Copy link
Contributor Author

CFrez commented Feb 18, 2021

I apologize for the excessive qty of commits, I accidentally started of a branch that had not been merged and I wanted to ensure those were not part of this commit.

@akrolsmir
Copy link
Contributor

This looks amazing! That screenshot really sells this PR :)

It looks like there are some tests that will need to be fixed up: https://app.circleci.com/pipelines/github/streamlit/streamlit/6698/workflows/165d4473-3b5b-447e-9057-9f6bbd615928/jobs/19160

st.multiselect.spec.js looks like a flake, and st_columns.spec.js probably just needs tweaking to look for the new flex values. st.image.spec will probably need to regenerate the image snapshot, though. Please let us know if you're having issues with any of those!

@CFrez
Copy link
Contributor Author

CFrez commented Feb 18, 2021

@akrolsmir I am having some problems with running tests locally. I am working through it, but I did adjust the column_spec so it will hopefully pass.

pretty sure st.multiselect.spec.js is a flake since it failed on my other pull request.

@CFrez
Copy link
Contributor Author

CFrez commented Feb 18, 2021

After, removing all global pip packages, clean installing pyenv and python, then running/fixing brew doctor. Everything is installing correctly now and all tests run. I should be able to work through and fix everything now.

Something unrelated, I believe, I keep getting failure on the data-frame demo locally...

@CFrez
Copy link
Contributor Author

CFrez commented Feb 19, 2021

@akrolsmir All checks have now passed!

@kmcgrady
Copy link
Collaborator

Hi @RedFrez Sorry for the delay! I took a look. Overall, this is positive addition, but I was concerned by the following:

  • The column percentage lends to more opportunity for a rounding error. Testing it but if the calculation is 0.001 percentage off, it could break the flow of elements. I think that number is reasonable considering I am not imagining large numbers of columns and advanced calculations and general precision of decimals.
  • Two different technologies using gap and padding-left seems complex. Left padding seems a little weird here already (I wish we could remove it), but I don't think it's a major concern, especially because of gap support.

Separately is use of gap property all together does not work in Safari for Flex Layouts. This should be addressed, but it would not change from the original implementation. I think an overall ideal solution in the future is to use CSS grid because it is much better supported than some grid features in flexbox. That being said, this may require a little retooling on how column information is sent down, which is an unnecessarily complex challenge.

I think overall it's still worth merging given above. Let me know if you have any thoughts.

@akrolsmir
Copy link
Contributor

Ah, great investigation, @kmcgrady ! Just some quick thoughts:

  • I hadn't considered the rounding error issue before! It feels like floating point precision in Python shouldn't generally result in errors that large (ie this kind of error), so I'm tentatively not that worried, but I'm glad you brought it up.
  • I do agree that the complexity is unfortunate. I believe @RedFrez did a great job of documenting the decisions behind this change on Github; could we also bring this context in the code, as a comment? I'd recommend either like a two-sentence summary of how the spacing is set, or linking back to this Github PR/issue

And the fact that gap is unsupported in Safari is actually quite annoying, and agreed that CSS grid may be a future ideal improvement. When I was first implementing this, I didn't have a particular principled reason behind choosing Flexbox over CSS Grid, and I'm happy to have that decision revisited!

Totally agreed that it's out of scope for this PR; and it's very much worth merging this improvement :)

@CFrez
Copy link
Contributor Author

CFrez commented Feb 23, 2021

This solution was what I determined would be the least change for accomplishing the current goal.

@kmcgrady I think it definitely would be better to have only gap or padding, but it would require for more information to be available for calculations. The potential break in flow could be accommodated by reducing the overall percentage a little bit which would have a little extra space available to grow into.

I wonder if Safari will end up following the path of IE… I did verify and the gap does not show up for flex.

From the aspect of use case, I do think Grid fits better since the content will never flow or wrap from one column to another. Grid could also provide opportunities for the future of adding rows to the columns that are aligned, versus having the create new columns.

The main downfall with Grid that I see, is that it requires extra work to make it flexible when the columns aren’t equal width. Also, it seems like the gap drives offsets with Grid regardless of if percentages or the fractional unit is used.

For either Grid or Flex, I think it would be helpful if the total qty of columns were passed to the styled component, as it would allow for calculation of padding that is needing to be adjusted for. I was trying to play with it some, but unfortunately I have limited Proto experience to be able to make any successful changes.

@akrolsmir I added a short comment for documentation to the Horizontal Block.

For this comment under StyledColumn:

    // The minimal viewport width used to determine the minimal
    // fixed column width while accounting for column proportions.
    // Randomly selected based on visual experimentation.

is it from old styling? Does it still apply or should it be removed?

Also, I don’t think the width property actually does anything with the current setup, and might be worth removing (after I re-verify it doesn’t actually affect anything if gone).

@kmcgrady
Copy link
Collaborator

@RedFrez that comment for StyledColumn is based on the theme.breakpoints.columns. Essentially we change how columns work based on an arbitrary viewport (less ideal, but it works for now). Maybe the placement is unfortunate, but it's still applies.

Looking at this. I'm going to merge it in. Thank you for your help in this!

@kmcgrady kmcgrady merged commit 4445aac into streamlit:develop Feb 24, 2021
@CFrez CFrez deleted the align_columns branch February 24, 2021 00:54
tconkling added a commit to tconkling/streamlit that referenced this pull request Feb 24, 2021
tconkling added a commit to tconkling/streamlit that referenced this pull request Feb 24, 2021
* develop:
  `watch_file` utility function (streamlit#2851)
  Align st.beta_columns  (streamlit#2811)
tconkling added a commit to tconkling/streamlit that referenced this pull request Feb 24, 2021
* develop:
  st.beta_secrets (streamlit#2757)
  `watch_file` utility function (streamlit#2851)
  Align st.beta_columns  (streamlit#2811)
tconkling added a commit that referenced this pull request Mar 1, 2021
* develop: (29 commits)
  Update bug_report.md
  Refactor CodeBlock.tsx (#2814)
  Remove copy button for empty codeblocks (#2808)
  Add image format deprecation config with expiration (#2865)
  Remove unneeded "use_column_width=True" from our doc examples (#2692)
  Extend our st.cache MagicMock handling logic to Mock (#2846)
  save work (#2862)
  Remove .stale-element class (#2848)
  Release 0.77 (#2849)
  Fix watchdog import failure (#2856)
  🔥 Fully remove `format` param from st.image (#2637)
  Don't memoize config._server_headless (#2858)
  hide empty columns on mobile (#2756)
  st.beta_secrets (#2757)
  `watch_file` utility function (#2851)
  Align st.beta_columns  (#2811)
  Update "showErrorDetails" config description and docs (#2841)
  Pause Dependabot updates for non-security-related issues (#2840)
  client.showTracebacks -> showErrorDetails (per product) (#2837)
  Color picker - show value (#2817)
  ...
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

Successfully merging this pull request may close these issues.

7 participants