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

Adds some GT table formatting functionalities #8662

Closed
wants to merge 17 commits into from

Conversation

Patowhiz
Copy link
Contributor

@Patowhiz Patowhiz commented Nov 23, 2023

Fixes partly issue #8554 #8541
Replaces PR #8615

@rdstern
Copy link
Collaborator

rdstern commented Feb 20, 2024

@Patowhiz delighted that even a new draft is there. I don't know whether I should be testing yet? When I try to go in it says:
image

It does then go in. I sort of expected the Format button to work, because that was where you were were working when in the UK. It doesn't seem to?

I also hope that Ana's work on the themes will soon be put back.

Tell me and @lilyclements when you are ready for us to look properly.

@Patowhiz
Copy link
Contributor Author

@rdstern you can now format title, subtitle, foot and source notes.
Foot notes can have expressions for the each columns. Only valid R expressions will yield results. You can have a look at the gt documentation of how to add expressions for foot notes. In future we could find a way of making it easy to add the expressions using a GUI instead of users having to type them.

As outlined in the package documentation, 'advanced' text formats are only supported for html output format. That means some text formats will be ignored if you export the table in other formats other than html. This is probably because the package uses CSS for these 'advanced' formats

@rdstern in regards to themes, I simply returned what was already implemented, I didn't delve into refactoring the code nor the design. Test for it's regression only not any additions.

The new additions are only available through Describe > Tables... dialog. Once merged they can be adapted to other tables that need the new features. I have deleted lots of now redundant code in this dialog. The aim was not to refactor it but rather show how gt table dialogs can now use the features added. Test for any regression in this dialog.

Kindly note that the PR doesn't fix all the items in the issues mentioned. We can keep building on top of what is currently here.

@Patowhiz Patowhiz marked this pull request as ready for review February 20, 2024 23:42
@Patowhiz Patowhiz changed the title Adds GT table functionalities Adds some GT table formatting functionalities Feb 20, 2024
@rdstern
Copy link
Collaborator

rdstern commented Feb 21, 2024

@lilyclements this has arrived just as I am boarding for the return to England. Very exciting, and I note that @Patowhiz seems to have been "burning the midnight oil" to update this pull request. Please can you check too?

Copy link
Collaborator

@rdstern rdstern left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Patowhiz very nice indeed so far.
a) I like the idea of the control for the footers. But how do I use the Column and Row expressions?
b) The Themes > Select Theme doesn't work yet, but it is a trivial fix to do. All the themes listed come from the gtExtras package. So you just have to add gtExtras:: in front of that element and they all work fine.

I'll check on the Manual themes next time.

There's more tabs to come, but @N-thony do you want to check too? As soon as these parts are working I would like to include this sub-dialog in the other commands and merge.

@Patowhiz
Copy link
Contributor Author

@rdstern thanks for testing this.
I have fixed the bugs that you found. Kindly retest.

In regards to columns and row expressions, like I said in the above comments, I'm still not sure how best to design a UI for making it easy for users to add the columns and row expressions. As outlined in the same comment, the documentation shows that footers can be used to make references to table cells. You do this by passing R expressions as parameters as shown in the example code below

# Add footnotes (the same text) to two different
# cell; data cells are targeted with `data_cells()`
gt_tbl <- 
  gt_tbl |>
  tab_footnote(
    footnote = "The Americas.",
    locations = cells_body(columns = name, rows = 3:4)
  )

The locations parameter shown in the above code is done for you by the dialog, So you simply type in the column name or expression (can be a vector etc, check on this documentation) and row expression as shown above.

The cells_body function also allows us to style those cells. We could add

@rdstern
Copy link
Collaborator

rdstern commented Feb 22, 2024

@Patowhiz I like the new controls and think you have gone a long way - broken the back? - of this task.
With the survey data I got this table:
image

Odd that the 1 at the bottom isn't on the same row as the footer?

Here is the current Footer for the table above:

image

The Column and Row fields need a pull-down to help with the options. My first suggestion (to keep the options and the pull-downs simple) is as follows:
a) Make it "shorter" so perhaps just the space for 3 rows, before it scrolls.
b) Repeat it 3 times! For the first, your current Footers Notes becomes a checkbox default checked with label Single.
c) The Column pull-down has the names of each column
d) The row pull-down just had the integers, with 1 to the number of rows.
e) The Headers become Column and Row. They could be a bit narrower for this option.
f) You choose just one of each.
g) There is also Title and Sub-title in the row pull down, so you could have a footer for eitrher.
h) There is a Stub option in the Columns so you can link the footer to any cell. (I think we will need a Stub tab?)

i) For the second instance of the control the checkbox has the label Multiple. Default unchecked, and the control is only visible if checked.
j) The header labels are Column(s), Row(s)
k) The column pull-down is again the different column names. But you can choose multiple columns to include. Then the code will add the c()
l) The row pull-down is either the numbers again, or some examples.
m) That's all. For Multiple it is only for the internal Cells of the table

n) For the third it is called General. The headers as for Multiple. The pull-down gives the different functions. You just choose one for each cell, and then complete that cell.

You may think of something much better. I am keen that you can have the single option without needing to know coding?

The general themes now works fine. I haven't checked the more complicated theme elements yet.

I hope the next update could also include the remaining tabs. They would be disabled, but we would know what's coming. I assume Nanoplots could be a tab?

@lilyclements
Copy link
Contributor

@Patowhiz this is looking great - really exciting stuff!

@Patowhiz
Copy link
Contributor Author

Patowhiz commented Apr 8, 2024

@rdstern I was able to have 2 footer grids; header and cells.

I managed to implement the header grid, which now has title and subtitle drop down. Note, you should only set the header footer when you supply the title or the subtitle values.

To implement a feature that allowed users to select the table columns, I would have to produce the gt table object then read the object to get the column names produced and populate them in a grid drop down. The gt package doesn't provide functions for reading the gt table object variables. I think their methodology assumes that you are meant to produce the table iteratively through code (meaning you are aware of the output already). Because of the package limitation, I'm not able to implement the feature you have suggested.

@Patowhiz
Copy link
Contributor Author

Patowhiz commented Apr 8, 2024

@rdstern I have also disabled alignment for now because I'm yet to find away of styling the footer superscript label to be consistent with alignment style. The footer superscript label is added by the gt package which by default styles the parent tag.

I'm contemplating enabling it for contents that don't have a footer link.

@rdstern
Copy link
Collaborator

rdstern commented Apr 9, 2024

This is looking nice, so far. Here is a table with some footnotes

image

a) Am I limited to numbers in these controls, so which row, or column it is. There could then be pull-downs?
b) How do I get a footnote attached to the header row. I assumed row 1, but it seems not? When I tried 0 it gave an error.
c) I also added atitle and sub-title - and with footnotes too. Nice.

image

d) The format option, above seems pretty comprehensive. Where is Bold?
e) The dialog always starts with None everywhere - could it start with the current settings for whatever is being formatted.

f) I look forward to the stub tab - I wonder whether that includes the summary variable, so we could choose to omit that column?

g) Then there is a lot to look forward to, on the remaining tabs. For example I need to be able to tailor the decimal places, choose whether NA could be replaced by blanks and so on. I assume there may need to be a Column, Row and Cell tab, but maybe not. I was wondering, on the footer tab, whether giving just the row, or just the column, could place the footer at the side, or top. But it just gave the footer with no anchor and then deleted that ro in your grid.

h) And I am excited about the nano-plots.

i) And how do I get nice banded tables - the sort that are so prominent in Excel?

You mentioned in UK that you were aiming for a set of tabs that would be better than those for the graphs. We have a lot to look forward to. It still needs a bit of a blitz though.

@Patowhiz
Copy link
Contributor Author

Patowhiz commented Apr 9, 2024

@rdstern

Bold is under the weight option.
Roger: - good - thanks

Would you be okay with me replacing "None" with "Default"? We currently lack a way to directly determine the current settings of the gt object intended to be produced.

Roger: Fine, of course.

I define the Header as the title and subtitle only, not the columns. You can see parts of a gt table here.

Roger: I think that corresponds to my point b above ? "How do I get a footnote attached to the header row. I assumed row 1, but it seems not? When I tried 0 it gave an error."
I am happy with your defining, but how does a user do that? Is that on another tab then?

The header footnote grid is designed to work with the title and subtitle. They are the only options in the grid. As I mentioned earlier, the title or subtitle must exist in the gt object, or you'll encounter an error. To avoid this, could we place this functionality under the header tab?

Regarding pull-downs for columns and rows, during my exploration of the package, most functionalities assume that the user will format the output iteratively. The inputs for the output are expected to come from the gt output itself. This differs from our dialogs where most inputs come from the data frame itself. For example, to implement the pull-downs you suggest, I would need to implement the ability to read the HTML output to determine the columns produced. It would have been easier if the gt object had such internal functions (which I haven't been able to find).

Roger: When I examine the code for the examples, I assume you are right, namely there is a lot of pre-processing (often including dplyr) and that stage finishes with a gt object. Then almost all the functions act on this object. I thought this was why you wanted to just do the second stage in the new dialog/sub-dialog. I assumed your dialog/sub-dialog would simply generate those different bits of R code - like the other dialogs. I must be missing something crucial?

Would you be open to expanding items g, h, and i in separate issues? You could explain the sample outputs you have in mind, and we can discuss the relevant implementation needed to achieve them.

Roger: I was kinda hoping that you would be doing the first draft of that? Especially after almost 6 months on this task.
I do that for the others, but always appreciate your take on this aspect of the work. And you have had a much more detailed read of gt than I have.

Updated the GtTable branch from master
@Patowhiz Patowhiz mentioned this pull request Jul 25, 2024
@Patowhiz Patowhiz closed this Jul 25, 2024
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.

4 participants