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

simplify the verbatim pop up #127

Merged
merged 8 commits into from
Dec 9, 2022
Merged

simplify the verbatim pop up #127

merged 8 commits into from
Dec 9, 2022

Conversation

Polkas
Copy link
Contributor

@Polkas Polkas commented Dec 7, 2022

closes #102

I simplify the code by placing the observe one module deeper.
I added a comment about shinyjs::useShinyjs() needed for disabled functionality, It was always needed but not documented.

Example app:

library(teal.code)
library(teal.widgets)
library(shiny)

ui <- fluidPage(
    verbatim_popup_ui("pop1", "Warnings1"),
    verbatim_popup_ui("pop2", "Warnings2"),
    shinyjs::useShinyjs()
)

server <- function(input, output, session) {
    
    
    disabled <- reactive({
        validate(need(TRUE, "This is a validation but it is being shown!"))
        warning("test")
    })
    
    verbatim_popup_srv(
        "pop1",
        title = "boo",
        verbatim_content = reactive("Hello"),
        disabled = reactive(TRUE)
    )
    verbatim_popup_srv(
        "pop2",
        title = "boo",
        verbatim_content = reactive("Hello"),
        disabled = reactive(FALSE)
    )
}

shinyApp(ui, server)

@Polkas Polkas added the core label Dec 7, 2022
@Polkas Polkas marked this pull request as ready for review December 8, 2022 10:48
@github-actions
Copy link
Contributor

github-actions bot commented Dec 8, 2022

Unit Tests Summary

    1 files      9 suites   12s ⏱️
  87 tests   85 ✔️ 2 💤 0
174 runs  172 ✔️ 2 💤 0

Results for commit c88c7c4.

♻️ This comment has been updated with latest results.

@Polkas Polkas requested a review from mhallal1 December 8, 2022 13:07
@gogonzo gogonzo self-assigned this Dec 9, 2022
Copy link
Contributor

@gogonzo gogonzo left a comment

Choose a reason for hiding this comment

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

This PR doesn't close #102 as validation error is still rendered on the button

main This branch
image image
pkgload::load_all("teal.widgets")
library(teal.code)
library(shiny)

ui <- fluidPage(
  verbatim_popup_ui("pop", "Warnings")
)

server <- function(input, output, session) {

  disabled <- reactive({
    validate(need(FALSE, "This is a validation but it is being shown!"))
    FALSE
  })

  verbatim_popup_srv(
    "pop",
    title = "boo",
    verbatim_content = reactive("Hello"),
    disabled = disabled
  )
}

shinyApp(ui, server)

@@ -61,7 +57,9 @@ verbatim_popup_ui <- function(id, button_label, type = c("button", "link"), ...)
#' @param style (`logical(1)`) whether to style the `verbatim_content` using `styler::style_text`.
#' If `verbatim_content` is a `condition` or `reactive` holding `condition` then this argument is ignored
#' @param disabled (`reactive(1)`) the `shiny` reactive value holding a `logical`. The popup button is disabled
#' when the flag is `TRUE` and enabled otherwise
#' when the flag is `TRUE` and enabled otherwise.
#' Please take into account that `shinyjs` is the dependency for this functionality so the `shinyjs::useShinyjs()` call
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we just include useShinyjs() in the UI of this element. It's a singleton so multiple calls shouldn't make a difference.

Copy link
Contributor

Choose a reason for hiding this comment

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

@Polkas what about this? Would you agree to include shinyjs::useShinyjs so we don't need to notify anyone.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

the package has the shinyjs dependency so not including it will NOT reduce the dependency for sb who want to use this functionality.
Then I agree with you that adding shinyjs::useShinyjs it is a good move.

Copy link
Contributor

@gogonzo gogonzo left a comment

Choose a reason for hiding this comment

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

👍

@Polkas Polkas merged commit 552365a into main Dec 9, 2022
@Polkas Polkas deleted the 102_hide_validate@main branch December 9, 2022 14:02
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 this pull request may close these issues.

verbatim popup with shiny validation or red error for disabled
2 participants