Skip to content

f7SmartSelect interfering NS for server-side module #217

@Esturban

Description

@Esturban

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions