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

[pt] add choose param #840

Merged
merged 1 commit into from Nov 5, 2023
Merged

[pt] add choose param #840

merged 1 commit into from Nov 5, 2023

Conversation

JanMarvin
Copy link
Owner

Works in Libreoffice

ping @vorpalvorpal

library(openxlsx2)

example_df <- data.frame(
  type = c("EU", "US", "US", "EU", "EU", "EU"),
  location = c("London", "NYC", "NYC", "Berlin", "Madrid", "London"),
  amount = c(7, 5, 3, 2.5, 6, 1)
)

wb <- wb_workbook() %>% 
  wb_add_worksheet() %>% 
  wb_add_data(x = example_df)

df <- wb_data(wb)

wb <- wb %>%
  wb_add_pivot_table(
    df, dims = "A3", rows = "location", filter = "type", data = "amount",
    slicer = "location", pivot_table = "pt1",
    param = list(
      choose = c(type = 'x=="EU"', 
                 location = 'x %in% c("London", "Madrid")')
      )
  )

if (interactive()) wb$open()

@JanMarvin
Copy link
Owner Author

library(openxlsx2)

example_df <- data.frame(
  type = c("EU", "US", "US", "EU", "EU", "EU"),
  location = c("London", "NYC", "NYC", "Berlin", "Madrid", "London"),
  amount = c(7, 5, 3, 2.5, 6, 1)
)

wb <- wb_workbook() %>% 
  wb_add_worksheet() %>% 
  wb_add_data(x = example_df)

df <- wb_data(wb)

wb <- wb %>%
  wb_add_pivot_table(
    df, dims = "A3", rows = "location", filter = "type", data = "amount",
    slicer = "location", pivot_table = "pt1",
    param = list(
      choose = c(type = 'x=="EU"')
    )
  ) %>% 
  wb_add_slicer(
    x = df, dims = "E2", 
    slicer = "location", pivot_table = "pt1", 
    param = list(
      choose = c(
        location = 'x %in% c("London", "Madrid")'
      )
    )
  )

if (interactive()) wb$open()

@JanMarvin
Copy link
Owner Author

JanMarvin commented Nov 5, 2023

There might be some quirks with escaped xml, like selecting "A&B" must be escaped as "A&amp;B", but I was to lazy to fix that correctly. Also I didn't test that it works correctly with item sorting, but it's a start.

@JanMarvin JanMarvin merged commit f50620e into main Nov 5, 2023
9 checks passed
@JanMarvin JanMarvin deleted the gh_issue_827 branch November 5, 2023 13:29
@vorpalvorpal
Copy link

Wow! That works great!
Sorry, I had meant to actually contribute something, but you beat me to it.

@JanMarvin
Copy link
Owner Author

Oops, haha. This was just in the back of my head and I was interested to see how the eval stuff would work.

There’s always something to do. Especially with testing and documenting all helping hands are more than welcome. And it’s kinda hard to test pivot table functionality with base R.

@JanMarvin JanMarvin mentioned this pull request Nov 23, 2023
6 tasks
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.

None yet

2 participants