RinteRface/shinyMobile

`f7SmartSelect` interfering NS for server-side module

Closed this issue · 3 comments

Hi,

I'm trying to build a module from your f7SmartSelect function and ran into an issue where the namespaces interfere for the select ui and the a call when defining the f7SmartSelect here:

id = inputId,

Is there are reason for this assignment? It seems to interfere with use in server-side rendering more than it is an issue in the UI. Please let me know.

For completeness, this is the module I am trying to build out:


smart_select_ui <- function(id, ...) {
  ns <- NS(id)
  uiOutput(ns("select-ui"), ...)
}

to_reactive<-function(x){
  if(!is.reactive(x)) return(reactive(x))
  return(x)
}

smart_select_server <-
  function(input,
           output,
           session,
           label,
           choices,
           selected = NULL,
           multiple = F,
           width = NULL,
           openIn = c('page', 'sheet', 'popup', 'popover'),
           ...) {
    session$ns -> ns
    label = to_reactive(label)
    choices = to_reactive(choices)
    selected = if(!is.null(selected)) to_reactive(selected) else reactive({
      req(choices())
      choices()[1]})
    multiple = to_reactive(multiple)
    width = to_reactive(width)
    openIn = to_reactive(openIn)

    output[['select-ui']] <- renderUI({
      print(ns("select"))
      # shinyMobile::f7SmartSelect(
      f7SmartSelect(
        inputId = "select",
        label = label(),
        choices = choices(),
        selected = selected(),
        multiple = multiple(),
        width = width(),
        openIn = openIn(),
        ...
      )
    })

    return(list(selected = reactive(input[['select']])))

  }

Testing it out in development, it seems commenting out the referenced line allows you to retain the reactivity on the server side and the ability to continue accessing the input

I have to check this one. Clearly, it is a mistake since id must be unique.

@Esturban : please give a try with remotes::install_github("RinteRface/shinyMobile@rc-1.0.0")

@DivadNojnarg: Thanks for your quick turnaround time ! Works and tested in deployment