Skip to content

Shiny app not working #68

Open
Open

Description

@pieterjanvc

Hello,

Let me start by saying I think it's great what's possible in this new version of Plumber!

I was particularly interested in running a Shiny app through the API, but unfortunately I cannot seem to make this work. Below is my (hopefully) reproducible example

#* Echo the parameter that was sent in
#*
#* @get /echo/<msg>
#*
#* @param msg:string The message to echo back.
#*
function(msg) {
  list(
    msg = paste0("The message is: '", msg, "'")
  )
}

#* @shiny /devApp
shiny::shinyAppDir(system.file("examples-shiny", "01_hello", package = "shiny"))

When I now click the Run API button in R Studio, the server starts, and the echo endpoint is working. However, if I navigate to the devApp endpoint I get {"error":"404 - Resource Not Found"}

Also the @shiny tag is not suggested in autocomplete and seems to be absent from the package

When I tried running

api() |>
  api_shiny(
    "/ui/",
    shiny::shinyAppDir(
      system.file("examples-shiny", "01_hello", package = "shiny")
    )
  ) |>
  api_run()

This did initially work when I navigated to the UI endpoint. However, now it's also broken giving me Internal Server Error (I tried installing the dev version and the the original one again so maybe that's the reason here?)

Thanks again for creating this new version!
PJ

Activity

  1. thomasp85 commented on Dec 15, 2025

    @thomasp85
    Collaborator

    Possible duplicate of #51

    I can sadly not replicate these shiny issues but since multiple people are reporting it I can only assume that it is a real issue in plumber2 or some platform specific issue. Can I get you to share your session info?

  2. jimbrig commented on Feb 20, 2026

    @jimbrig

    @thomasp85 - same issue for me still. looking into it further.

  3. jimbrig commented on Apr 27, 2026

    @jimbrig

    @thomasp85 - following up with some additional testing.

    Good news: both api_shiny() and the @shiny roxygen2 tag work correctly.

    What was tested

    Both registration approaches work:

    # Programmatic
    api() |>
      api_shiny(
        "/ui",
        shiny::shinyAppDir("/absolute/path/to/shiny/app")
      ) |>
      api_run()
    # plumber.R roxygen2 tag
    
    #* @shiny /my_app/
    shiny::shinyAppDir('/absolute/path/to/shiny/app')

    Both result in a fully functional Shiny session; the WebSocket handshake completes, inputs are initialized, and outputs render correctly.


    A few findings worth noting below that may or may not be worth pursuing more, but thought I'd mention them:

    Trailing slash on the access URL

    Regardless of whether the path is registered as /ui or /ui/, the app only serves correctly when navigating to the trailing-slash URL in the browser (http://127.0.0.1:8080/ui/). This is expected behavior given how browsers resolve relative asset paths from an HTML document, not a routing bug, but it is easy to get wrong initially since its all silent, i.e. shiny routes don't appear in the OpenAPI __docs__ interface, there's no auto-launch behavior for mounted apps, and the natural URL to try is whatever path string was passed to api_shiny(), which without the slash fails silently even when provided a slash-less route (i.e. "/ui" vs "/ui/").

    A small quality-of-life improvement that would eliminate this entirely could be a startup message from api_run() noting the correct access URL for each mounted Shiny app, e.g.:

    ℹ Shiny app mounted at http://127.0.0.1:8080/ui/
    

    using the cli URL markup etc.

    No routing changes needed, just surfacing the correct URL at run time would be enough

    shinyAppDir() path resolution

    Relative paths passed to shinyAppDir() fail with ! No Shiny application exists at the path "./app". Absolute paths work fine. This may be a working directory mismatch between the R session's getwd() and the directory containing plumber.R but may be worth investigating whether plumber2 should normalize the working directory when sourcing the file, or at minimum document that absolute paths are required.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions