Appsilon/shiny.router

[Bug]: Error: 'router_ui' is not an exported object from 'namespace:shiny.router'

bathyscapher opened this issue · 2 comments

Guidelines

  • I agree to follow this project's Contributing Guidelines.

Project Version

0.2.2

Platform and OS Version

MacOS Monterey 12.3.1 (Apple Chip, M1)

Existing Issues

seems no

What happened?

I just successfully installed shiny.router with R 4.2.0 on a MacOS Monterey 12.3.1 (Apple Chip, M1):

> install.packages("shiny.router")
> packageVersion("shiny.router")
[1] ‘0.2.2’

I can access the man page of the function router_ui() with and without double colon operators...

> ?router_ui
> ?shiny.router::router_ui

... as seen here in this screenshot from RStudio:

But, when I try to run, for example, this example from your tutorial/blog page...

library(shiny)
library(shiny.router)

# This creates UI for each page.
page <- function(title, content) {
  div(
    titlePanel(title),
    p(content),
    uiOutput("power_of_input")
  )
}

# Part of both sample pages.
home_page <- page("Home page", "This is the home page!")
side_page <- page("Side page", "This is the side page!")

# Callbacks on the server side for the sample pages
home_server <- function(input, output, session) {
  output$power_of_input <- renderUI({
    HTML(paste(
      "I display <strong>square</strong> of input and pass result to <code>output$power_of_input</code>: ", 
      as.numeric(input$int) ^ 2))
  })
}

side_server <- function(input, output, session) {
  output$power_of_input <- renderUI({
    HTML(paste(
      "I display <strong>cube</strong> of input and <strong>also</strong> pass result to <code>output$power_of_input</code>: ", 
      as.numeric(input$int) ^ 3))
  })
}

# Create routing. We provide routing path, a UI as well as a server-side callback for each page.
router <- make_router(
  route("home", home_page, home_server),
  route("side", side_page, side_server)
)

# Create output for our router in main UI of Shiny app.
ui <- shinyUI(fluidPage(
  shiny::sliderInput("int", "Choose integer:", -10, 10, 1, 1),
  router_ui()
))

# Plug router into Shiny server.
server <- shinyServer(function(input, output, session) {
  router(input, output, session)
})

# Run server in a standard way.
shinyApp(ui, server)

... R throws the error Error in router_ui() : could not find function "router_ui".

I tried to specify the package with double colons...

shiny.router::router_ui()

... what yields the error Error: 'router_ui' is not an exported object from 'namespace:shiny.router'.

I verified that the package is loaded via adding packageVersion() and getAnywhere() right after reading the libraries (here, I outcommented router_ui() to make it "run")...

> library(shiny)
> library(shiny.router)

> print(packageVersion("shiny.router"))
> print(getAnywhere(router_ui))
> ...
[1] ‘0.2.2A single object matchingrouter_uiwas found
It was found in the following places
  namespace:shiny.router
with value

function (router) 
{
    shiny::addResourcePath("shiny.router", system.file("www", 
        package = "shiny.router"))
    js_file <- file.path("shiny.router", "shiny.router.js")
    css_file <- file.path("shiny.router", "shiny.router.css")
    list(shiny::singleton(shiny::withTags(shiny::tags$head(shiny::tags$script(type = "text/javascript", 
        src = js_file), shiny::tags$link(rel = "stylesheet", 
        href = css_file)))), shiny::tags$div(id = "router-page-wrapper", 
        lapply(router$routes, function(route) route$ui)))
}
<bytecode: 0x105b37c10>
<environment: namespace:shiny.router>

... what also showed that shiny.router is properly installed and router_ui() should be accessible.

Do you have any clue what's wrong here? Sorry, in case I might have overlooked something...
Thank you!

Steps to reproduce

  1. Install shiny.router version 0.2.2 from CRAN (on a MacOS Monterey 12.3.1 (Apple Chip, M1?)
  2. Run this example from your blog page

Expected behavior

I would expect R to find the function router_ui() and open the app.

Attachments

No response

Screenshots or Videos

No response

Additional Information

No response

Hi @bathyscapher

That code example is found in an outdated version of the blog post. When I analyze the updated version at https://appsilon.com/shiny-router-020/ I see no mention of router_ui(). This function seem to be deprecated. Please check out the current documentation.

Okay, this was not obvious to me. Sorry, if I may have overlooked the note at the beginning of the page (although I doubt it was there some weeks ago...). Thank you though :)