Appsilon / shiny.semantic

Shiny support for powerful Fomantic UI library.
http://appsilon.github.io/shiny.semantic
Other
497 stars 96 forks source link

[Bug]: as_is parameter in modal-related functions is not functional #436

Closed federiva closed 1 year ago

federiva commented 1 year ago

Guidelines

Project Version

No response

Platform and OS Version

No response

Existing Issues

No response

What happened?

An already closed #348 introduced the as_is parameter to be passed to the hide_modal, show_modal and remove_modal functions. This parameter, a logical, is not being handled in the body of the function itself causing this functions to always work as if they were passing the as_is = FALSE which is confusing because the default for this parameter is TRUE

Steps to reproduce

library(shiny)
library(shiny.semantic)

mod_ui <- function(id) {
  ns <- NS(id)
  tagList(
    shiny.semantic::modal(
      div("Inspect the server code"),
      id = ns("modal")
    ),
    # The following should not work but it's working because asis is always as FALSE
    shiny.semantic::action_button(
      input_id = ns("open_as_is_true"),
      class = "red",
      "Open modal with as_is TRUE passing the non-namespaced id"
    ),
    # The following should work but it's not
    shiny.semantic::action_button(
      input_id = ns("open_as_is_true_namespaced"),
      class = "red",
      "Open modal with as_is TRUE passing the namespaced id"
    ),
    # The following is working as expected because asis is always as FALSE
    shiny.semantic::action_button(
      input_id = ns("open_as_is_false"),
      class = "yellow",
      "Open modal with as_is FALSE passing the non-namespaced id"
    ),
    hr(),
    h3("shiny.semantic::show_modal Source code:"),
    div(
      div(style = "font-family: monospace; background-color: #f4f4f4; color: #c7254e; padding: 5px; border: 1px solid #ccc;",
        HTML(
        '&emsp;function (id, session = shiny::getDefaultReactiveDomain(), asis = TRUE) {<br>
            &emsp;&emsp;id <- ifelse(inherits(session, "session_proxy"), session$ns(id), id)<br>
            &emsp;&emsp;session$sendCustomMessage("showSemanticModal", list(id = id, action = "show"))<br>
          &emsp;}'
        )
      )
    )
  )
}

mod_server <- function(id) {
  moduleServer(id, function(input, output, session) {
    observeEvent(input$open_as_is_true, {
      shiny.semantic::show_modal(
        id = "modal",
        asis = TRUE
      )
    })

    observeEvent(input$open_as_is_true_namespaced, {
      shiny.semantic::show_modal(
        id = session$ns("modal"),
        asis = TRUE
      )
    })

    observeEvent(input$open_as_is_false, {
      shiny.semantic::show_modal(
        id = "modal",
        asis = FALSE
      )
    })
  })
}

ui <- shiny.semantic::semanticPage(
  mod_ui("modal")
)

server <- function(input, output, session) {
  mod_server("modal")
}

shinyApp(ui, server)

Expected behavior

As declared in the UI function

Attachments

No response

Screenshots or Videos

No response

Additional Information

No response

federiva commented 1 year ago

Closed by #437