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

introduce decorators for tm_data_table #799

Merged
merged 17 commits into from
Nov 22, 2024

Conversation

m7pr
Copy link
Contributor

@m7pr m7pr commented Nov 19, 2024

Part of insightsengineering/teal#1370

Working Example
devtools::load_all("../teal")
devtools::load_all(".")

# general data example
data <- teal_data()
data <- within(data, {
  require(nestcolor)
  iris <- iris
})

custom_table_decorator_interactive <- teal_transform_module(
  ui = function(id) {
    ns <- NS(id)
    div(
      selectInput(
        ns("style"), 
        "Table Style", 
        choices = c("Default", "Striped", "Hover"), 
        selected = "Default"
      )
    )
  },
  server = function(id, data) {
    moduleServer(id, function(input, output, session) {
      reactive({
        req(data(), input$style)
        within(data(), 
               {
                 if (style == "Striped") {
                   table <-
                     DT::formatStyle(
                       table,
                       columns = attr(table$x, "colnames")[-1],
                       target = 'row',
                       backgroundColor = '#f9f9f9'
                     )
                 } else if (style == "Hover") {
                   table <-
                     DT::formatStyle(
                       table,
                       columns = attr(table$x, "colnames")[-1],
                       target = 'row',
                       backgroundColor = '#f0f0f0'
                     )
                 }
               }, 
               style = input$style
        )
      })
    })
  }
)

app <- init(
  data = data,
  modules = modules(
    tm_data_table(
      variables_selected = list(
        iris = c("Sepal.Length", "Sepal.Width", "Petal.Length", "Petal.Width", "Species")
      ),
      dt_args = list(caption = "IRIS Table Caption"),
      decorators = list(custom_table_decorator_interactive)
    )
  )
)
if (interactive()) {
  shinyApp(app$ui, app$server)
}

@m7pr m7pr added the core label Nov 19, 2024
@m7pr m7pr changed the base branch from main to 1187_decorate_output@main November 19, 2024 13:24
@m7pr m7pr changed the title WIP introduce decorators for tm_data_table introduce decorators for tm_data_table Nov 21, 2024
@m7pr m7pr marked this pull request as ready for review November 21, 2024 11:49
@m7pr m7pr requested a review from averissimo November 21, 2024 11:50
@m7pr
Copy link
Contributor Author

m7pr commented Nov 21, 2024

Hey @averissimo this PR is done, however I would need some extra pair of 👁️ eyes.

This example for for non-ineractive decorator. However it fails for interactive decorator because inside the within function, it can not find input$style. It is empty. So I think I put UI part in the wrong place inside the code.

Would you maybe be able to take a look?

R/tm_data_table.R Outdated Show resolved Hide resolved
Copy link
Contributor

@averissimo averissimo left a comment

Choose a reason for hiding this comment

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

Show R code is not working and there will be a linter error

R/tm_data_table.R Outdated Show resolved Hide resolved
R/tm_data_table.R Outdated Show resolved Hide resolved
R/tm_data_table.R Outdated Show resolved Hide resolved
@averissimo
Copy link
Contributor

averissimo commented Nov 22, 2024

The **CURRENT** implementation of data-table has for each of the datanames:

  • 1 call of decorator UI/SRV
    • So each may have a different UI with options specific to each tab

Q: Do we want to try and create a "singleton" UI that then applies to each one dataname?

In practice: Do we want to have a single UI for options applied to each dataname, or a UI for each of the datanames (as is now)

Consequences: We need get inputs from 1-level above as the srv_teal_transform_data is called from within the dataname prefixed namespace (data_table-{iris,mtcars, ...})


Current implementation vs. Q

edit: note that every sub-box is a tab in the module.

image

Copy link
Contributor

@averissimo averissimo left a comment

Choose a reason for hiding this comment

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

LGTM 🎉

@averissimo averissimo merged commit fb28571 into 1187_decorate_output@main Nov 22, 2024
@averissimo averissimo deleted the tm_data_table@1187_output@main branch November 22, 2024 17:55
@github-actions github-actions bot locked and limited conversation to collaborators Nov 22, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants