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

[Bug]: Plot resizing on filter panel toggling stops when filters modified #251

Closed
3 tasks done
chlebowa opened this issue Jul 29, 2024 · 0 comments · Fixed by #252
Closed
3 tasks done

[Bug]: Plot resizing on filter panel toggling stops when filters modified #251

chlebowa opened this issue Jul 29, 2024 · 0 comments · Fixed by #252
Labels

Comments

@chlebowa
Copy link
Contributor

chlebowa commented Jul 29, 2024

What happened?

Toggling the filter panel should cause the plots in the output. This works when the app starts but stops working when filters are modified.

example app
library(teal.widgets)
library(teal)
library(teal.modules.general)

data <- teal_data() |>
  within(iris <- iris) |>
  within(mtcars <- mtcars) |>
  within({
    add_nas <- function(x) {
      x[sample(seq_along(x), floor(length(x) * runif(1, .05, .17)))] <- NA
      x
    }
    iris[] <- lapply(iris, add_nas)
    mtcars[] <- lapply(mtcars, add_nas)
    mtcars[["cyl"]] <- as.factor(mtcars[["cyl"]])
    mtcars[["gear"]] <- as.factor(mtcars[["gear"]])
  })
datanames(data) <- c("iris", "mtcars")
modules <- modules(
  tm_g_distribution(
    label = "dist1",
    dist_var = data_extract_spec(
      dataname = "iris",
      select = select_spec(variable_choices("iris"), "Petal.Length")
    )
  ),
  tm_missing_data(
    label = "missing",
    ggplot2_args = list(
      "Combinations Hist" = ggplot2_args(
        labs = list(subtitle = "Plot produced by Missing Data Module", caption = NULL)
      ),
      "Combinations Main" = ggplot2_args(labs = list(title = NULL))
    )
  ),
  example_module("Example One"),
  example_module("Example Two", "mtcars")
)
filter <- teal_slices(
  teal_slice("iris", "Species", choices = c("virginica", "versicolor"), selected = "virginica"),
  teal_slice("mtcars", "cyl", selected = 6),
  module_specific = TRUE,
  mapping = list(
    "Example Two" = "mtcars cyl",
    "global_filters" = "iris Species"
  )
)

app <- init(
  data = data,
  modules = modules,
  filter = filter
)
runApp(app)

The bug apparently results from replacing the plot container div in the DOM when the plot is recreated after filtering and the ResizeObserver losing sight of it. The solution is to not disconnect the MutationObserver that activates the ResizeObserver.

Fix incoming.

sessionInfo()

> packageVersion("teal.widgets")
[1] '0.4.2.9014'

Relevant log output

No response

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.
@chlebowa chlebowa added the bug label Jul 29, 2024
@m7pr m7pr closed this as completed in #252 Sep 3, 2024
m7pr added a commit that referenced this issue Sep 3, 2024
Fixes #251 

The `MutationObserver` that activates `ResizeObserver` is not
disconnected after activation.

Co-authored-by: Dony Unardi <[email protected]>
Co-authored-by: Marcin <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant