insightsengineering / teal.slice

Reproducible slice module for teal applications
https://insightsengineering.github.io/teal.slice/
Other
11 stars 5 forks source link

[Bug]: Wrong counts when `fixed = TRUE` and `count_type = "none"` #476

Closed gogonzo closed 9 months ago

gogonzo commented 1 year ago

What happened?

When teal_slice(..., fixed = TRUE, count_type = FALSE) wrong counts are being displayed in ChoicesFilterState. When count_type = FALSE counts should be "level_i (n_i)" and now it is "level_i (n_i/N)".

sessionInfo()

library(teal)

nest_logo <- "https://raw.githubusercontent.com/insightsengineering/hex-stickers/main/PNG/nest.png"

app <- init(
  data = teal.data::teal_data(
    IRIS = iris,
    MTCARS = mtcars,
    code = quote({
      IRIS <- iris
      MTCARS <- mtcars
    })
  ),
  filter = teal_slices(
    teal_slice(dataname = "IRIS", varname = "Species", fixed = TRUE, count_type = FALSE),
    allow_add = FALSE
  ),
  modules = modules(example_module()),
  header = tags$span(
    style = "display: flex; align-items: center; justify-content: space-between; margin: 10px 0 10px 0;",
    tags$head(tags$link(rel = "shortcut icon", href = nest_logo), tags$title("Basic Teal Demo App")),
    tags$span(
      style = "font-size: 30px;",
      "My first teal app"
    ),
    tags$span(
      style = "display: flex; align-items: center;",
      tags$img(src = nest_logo, alt = "NEST logo", height = "45px", style = "margin-right:10px;"),
      tags$span(style = "font-size: 24px;", "NEST @ Roche")
    )
  ),
  footer = tags$p(
    actionLink("showAboutModal", "About,"),
    tags$a(
      href = "https://github.com/insightsengineering/teal.gallery/tree/main/basic-teal",
      target = "_blank",
      "Source Code,"
    ),
    tags$a(
      href = "https://github.com/insightsengineering/teal.gallery/issues",
      target = "_blank",
      "Report Issues"
    )
  )
)

body(app$server)[[length(body(app$server)) + 1]] <- quote(
  observeEvent(input$showAboutModal, {
    showModal(modalDialog(
      tags$p("This teal app is brought to you by the NEST Team at Roche/Genentech. For more information, please visit:"),
      tags$ul(
        tags$li(tags$a(
          href = "https://github.com/insightsengineering", "Insights Engineering",
          target = "blank"
        )),
        tags$li(tags$a(
          href = "https://pharmaverse.org", "Pharmaverse",
          target = "blank"
        ))
      ),
      easyClose = TRUE
    ))
  })
)

shinyApp(app$ui, app$server)

Relevant log output

No response

Code of Conduct

Contribution Guidelines

Security Policy

donyunardi commented 11 months ago

Slight fix on the code provided above:

Updated code:

library(teal)

nest_logo <- "https://raw.githubusercontent.com/insightsengineering/hex-stickers/main/PNG/nest.png"

app <- init(
  data = teal.data::teal_data(
    IRIS = iris,
    MTCARS = mtcars,
    code = quote({
      IRIS <- iris
      MTCARS <- mtcars
    })
  ),
  filter = teal_slices(
    teal_slice(dataname = "IRIS", varname = "Species", fixed = TRUE), # fixed this line
    count_type = "none", # fixed this line
    allow_add = FALSE
  ),
  modules = modules(example_module()),
  header = tags$span(
    style = "display: flex; align-items: center; justify-content: space-between; margin: 10px 0 10px 0;",
    tags$head(tags$link(rel = "shortcut icon", href = nest_logo), tags$title("Basic Teal Demo App")),
    tags$span(
      style = "font-size: 30px;",
      "My first teal app"
    ),
    tags$span(
      style = "display: flex; align-items: center;",
      tags$img(src = nest_logo, alt = "NEST logo", height = "45px", style = "margin-right:10px;"),
      tags$span(style = "font-size: 24px;", "NEST @ Roche")
    )
  ),
  footer = tags$p(
    actionLink("showAboutModal", "About,"),
    tags$a(
      href = "https://github.com/insightsengineering/teal.gallery/tree/main/basic-teal",
      target = "_blank",
      "Source Code,"
    ),
    tags$a(
      href = "https://github.com/insightsengineering/teal.gallery/issues",
      target = "_blank",
      "Report Issues"
    )
  )
)

body(app$server)[[length(body(app$server)) + 1]] <- quote(
  observeEvent(input$showAboutModal, {
    showModal(modalDialog(
      tags$p("This teal app is brought to you by the NEST Team at Roche/Genentech. For more information, please visit:"),
      tags$ul(
        tags$li(tags$a(
          href = "https://github.com/insightsengineering", "Insights Engineering",
          target = "blank"
        )),
        tags$li(tags$a(
          href = "https://pharmaverse.org", "Pharmaverse",
          target = "blank"
        ))
      ),
      easyClose = TRUE
    ))
  })
)

shinyApp(app$ui, app$server)

Acceptance Criteria: