Search code examples
shinyshinydashboardshinymodules

rhino modules for shiny app - my app does not work


I'm trying to learn the rhino modules to develop R shiny apps but got stuck with this simple app:

app/view/page1.R

box::use(
    shiny[moduleServer, textOutput, renderText, NS, div],
    shiny.fluent[TextField.shinyInput, Stack]
)

#' @export
ui <- function(id){
    ns <- NS(id)
    Stack(TextField.shinyInput(ns("page1input"), value = "default value"),
          textOutput(ns('page1print'))
          )
}

#' @export
server <- function(id) {
    moduleServer(id, function(input, output, session){
        output$page1print <- renderText(sprintf("Input from above: %s", input$page1input))
    })
}

main.R

box::use(
  shiny[div, moduleServer, NS, renderUI, tags, uiOutput, renderText],
  shiny.fluent[fluentPage]
)

box::use(
  app/view/page1
)

#' @export
ui <- function(id) {
  ns <- NS(id)
  fluentPage(
    page1$ui('p1')
  )
}

#' @export
server <- function(id) {
  moduleServer(id, function(input, output, session) {
    page1$server('p1')
  })
}

I expect the app to print the user's input but it doesn't. Could anyone help? Thanks a lot


Solution

  • You forgot to add namespacing to your call to page1$ui

    # main.R
    
    #' @export
    ui <- function(id) {
      ns <- NS(id)
      fluentPage(
        page1$ui(ns('p1')) # <- fixed here
      )
    }
    

    Now main$server is able to read inputs from page1$ui. Don't worry, everyone makes this mistake several times ;).