Skip to content

[Feature Request]: Master Filter for common columns across datasets #620

@shahr43

Description

@shahr43

Feature description

Hello, we have a use case where we need to filter across datasets. I have modified the example from the vignette to explain what I mean.

library(shiny)
library(teal.slice)

df1 <- data.frame(col1 = c(2, 3, 5, 7, 9), col2 = rnorm(5))
df2 <- data.frame(col1 = 1:5, col3 = rnorm(5))
# create a FilteredData object
datasets <- init_filtered_data(list(df1 = df1, df2 = df2))

# setting initial state
set_filter_state(
  datasets = datasets,
  filter = teal_slices(
    teal_slice(dataname = "df1", varname = "col1"),
    teal_slice(dataname = "df2", varname = "col2"),
    count_type = "all",
    allow_add = TRUE
  )
)

ui <- fluidPage(
  fluidRow(
    column(
      width = 9,
      tabsetPanel(
        tabPanel(title = "df1", dataTableOutput("df1_table")),
        tabPanel(title = "df2", dataTableOutput("df2_table"))
      )
    ),
    # ui for the filter panel
    column(width = 3, datasets$ui_filter_panel("filter_panel"))
  )
)

server <- function(input, output, session) {
  # this is the shiny server function for the filter panel and the datasets
  # object can now be used inside the application
  datasets$srv_filter_panel("filter_panel")
  
  # get the filtered datasets and put them inside reactives for analysis
  df1_filtered_data <- reactive(datasets$get_data(dataname = "df1", filtered = TRUE))
  df2_filtered_data <- reactive(datasets$get_data(dataname = "df2", filtered = TRUE))
  
  output$df1_table <- renderDataTable(df1_filtered_data())
  output$df2_table <- renderDataTable(df2_filtered_data())
}

shinyApp(ui, server)

Here as you can see there is a common column indf1 and df2 i.e col1. We need to have a "master filter" in place which shows this common column once for both the datasets. It will have range from 1 to 9 since that is the min and max range combined in both the datasets and whatever the filter values are selected here it will be applied to both the datasets and they will be filtered by the value.

Let me know if you have any questions or my explanation is unclear.

Do you think this is possible to be done using teal.slice ?

Code of Conduct

  • I agree to follow this project's Code of Conduct.

Contribution Guidelines

  • I agree to follow this project's Contribution Guidelines.

Security Policy

  • I agree to follow this project's Security Policy.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions