I'm running shiny::runApp() with random port assignment. I can't figure out how to print the port number shiny was assigned to. Hoping someone can help me.
This is how I wrote my app.
app.R
library(shiny)
# Define UI for app that draws a histogram ----
ui <- fluidPage(
# App title ----
titlePanel("Hello Shiny!")
)
server <- function(input, output) {
}
shinyApp(ui, server)
and then I ran it with: R -e "shiny::runApp()"
How do I get the port number the shiny app is listening to?
Thank you!
By default shiny runs on a random port. You can use the port argument in the runApp function to specify one, or set it in options with the shiny.port option.
You can get the current port the client is using in the session$clientData$url_port object. So in your example:
server <- function(input, output, session) {
print(isolate(session$clientData$url_port))
}
This would print the port the user is using to the console, but you can save it in a variable if you need to use it in the app.
@olechnwin Could you set a fixed port number? options(shiny.port = 12345) at the top of the file would let you run it and always send the user to mydomain.com:12345. You could also try to run shiny::runApp(launch.browser = TRUE)
I think Shiny Server or Connect might be the way to go for having multiple users connect to your application on the same machine. You can install an open-source shiny server and that will handle all of the concurrent sessions for you.
Thank for your suggestions. I'm trying to avoid having to put my app online. There are lots of hoops to jump through to get permission. Plus, the users will be people inside my organization.
That shouldn't be an issue. You could have the hostname set to localhost or set it to a non-routable IP address so only other devices on your network could access it.