How to integrate shiny input into plumber

Hey Shiny and Plumber experts,

Basically, we are trying to pass the output of shiny via Plumber to other programmers to integrate in an webpage.

From the documentation, running on local machine,
following works individually:

Plumber reprex

#* Plot a histogram
#* @png
#* @get /plot
function(){
  random_num <- rnorm(10) * 5
  hist(random_num)
}
saving the file as plumber.R
# Running the below in console 
r <- plumb("plumber.R")  # Where 'plumber.R' is the location of the file shown above
r$run(port=8000)

# Now, loading the browser: http://127.0.0.1:8000/__swagger__/ 
![image|604x500](upload://yI7ZB17kMWN9QJuS005953WDznp.png) 

Similarly shiny reprex :

library(shiny)
# Define UI for application that plots random distributions 
ui = shinyUI(fluidPage(
  
  # Application title
  titlePanel("Hello Shiny!"),
  
  # Sidebar with a slider input for number of observations
  sidebarLayout(
    sidebarPanel(
      sliderInput("obs", 
                  "Number of observations:", 
                  min = 1, 
                  max = 1000, 
                  value = 500)
    ),
    
    # Show a plot of the generated distribution
    mainPanel(
      plotOutput("distPlot")
    )
  )
))

# Define server logic required to generate and plot a random distribution
server = shinyServer(function(input, output) {
  
  # Expression that generates a plot of the distribution. The expression
  # is wrapped in a call to renderPlot to indicate that:
  #
  #  1) It is "reactive" and therefore should be automatically 
  #     re-executed when inputs change
  #  2) Its output type is a plot 
 
  output$distPlot <- renderPlot({
    
    # generate an rnorm distribution and plot it
    dist <- rnorm(input$obs)
    hist(dist)
  })
  
})

# Run the app
shinyApp(ui, server)

How can we render shiny's output i.e histogram into plumber's swagger ?

i.e. How to display the user

Tried: Embedding the plumber function within Shiny's renderFunction

library(shiny)
# Define UI for application that plots random distributions 
ui = shinyUI(fluidPage(
  
  # Application title
  titlePanel("Hello Shiny!"),
  
  # Sidebar with a slider input for number of observations
  sidebarLayout(
    sidebarPanel(
      sliderInput("obs", 
                  "Number of observations:", 
                  min = 1, 
                  max = 1000, 
                  value = 500)
    ),
    
    # Show a plot of the generated distribution
    mainPanel(
      plotOutput("distPlot")
    )
  )
))

# Define server logic required to generate and plot a random distribution
server = shinyServer(function(input, output) {
  
  # Expression that generates a plot of the distribution. The expression
  # is wrapped in a call to renderPlot to indicate that:
  #
  #  1) It is "reactive" and therefore should be automatically 
  #     re-executed when inputs change
  #  2) Its output type is a plot 
 

  #### Embedding inside the shiny
  output$distPlot <- renderPlot({
    #* Plot a histogram
    #* @png
    #* @get /plot
    function(){
    # generate an rnorm distribution and plot it
    dist <- rnorm(input$obs)
    hist(dist)
    }
  })
  
})

shinyApp(ui, server)

(As of writing this...)
In the cran version of plumber, the swagger output can not be updated.

In the GitHub version of plumber, the swagger output can be updated by supplying a function to the swagger argument of $run(). This design will change in the next month and a proper function will be provided.


Safe choice until plumber is released (looking at end of May?) is to wait. :disappointed:

This topic was automatically closed 54 days after the last reply. New replies are no longer allowed.