I am building a web application using java (backend) and javascript. At some point my application retrieves some specific data from a remote database. I want to embed a shiny app in my web-application that reads, analyses and visualizes this data. The data that is retrieved is dependent on user interaction with my application.
So basically I am trying to send data to a shiny app (possibly using REST). Is this possible?
Just to add an example: if you want to:
plumber
httr
A minimal example of using httr
to load some JSON data (from OpenCPU) in Shiny:
library(shiny)
library(httr)
library(dplyr)
ui <- fluidPage(
tableOutput("tbl")
)
server <- function(input, output, session) {
output$tbl <- renderTable( {
# GET request from an API
req <- httr::GET(url = "cran.ocpu.io/ggplot2/data/msleep/json")
req_parsed <- httr::content(req, type = "application/json")
# Convert to data.frame
dplyr::bind_rows(req_parsed)
})
}
shinyApp(ui, server)
Of course you can! An R Shiny app can receive data in the same ways any web app can. E.g. it could run an internal timer to go and fetch data from an API, scrape data from the web, or access a database.
Some suggestions
plumber
package would be a good place to startTwo of the most used scraping packages are rvest
and (Hadley Wickham's) httr
. These are a great start for accessing APIs or scraping raw data from anywhere on the web
If you wanted to connect to a database, I recommend deciding which one you'll use then googling how to connect to it using R. Once you've succeeded, you can move that code inside the Shiny app!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With