Is it possible to render the html that i get from httr::POST
inside a shiny app? For example, suppose I have the following plumber api:
library(plumber)
library(threejs)
#* Returns threejs htmlwidget
#* @param data json with x y z
#* @post /threejs
#* @serializer htmlwidget
threejs <- function(data){
scatterplot3js(data$x,data$y,data$z, color=rainbow(length(data$z)))
}
Using httr
i can use that api to generate a plot:
library(shiny)
library(jsonlite)
library(httr)
z <- seq(-10, 10, 0.01)
x <- cos(z)
y <- sin(z)
response <- httr::POST(url = 'http://127.0.0.1:9601/threejs',
body = list(data = list(x = x,
y = y,
z = z)),
encode="json")
cat(content(response, "text"), file="temp.html")
Is there a way to render that inside a shiny app? I tried the following
library(shiny)
library(jsonlite)
library(httr)
z <- seq(-10, 10, 0.01)
x <- cos(z)
y <- sin(z)
response <- httr::POST(url = 'http://127.0.0.1:9601/threejs',
body = list(data = list(x = x,
y = y,
z = z)),
encode="json")
# cat(content(response, "text"), file="temp.html")
#ui
ui <- fluidPage(
# Application title
titlePanel("Testing Plumber"),
sidebarLayout(
sidebarPanel(
),
mainPanel(
tags$html(HTML(content(response, "text")))
)
)
)
# Define server logic required to draw a histogram
server <- function(input, output) {
}
# Run the application
shinyApp(ui = ui, server = server)
Alas, it does not work as. Thanks for the help!