Hello, @cole. Thank you so much for your answer.
I've been researching about creating REST API's. I found the plumber package and opencpu package with the help of colleagues from a Facebook community.
According to my research, I realized that opencpu is more appropriate because it is more general and presents several ways to solve security and scalability problems. While the plumber is simpler.
In this way, I decided to create a REST API using the opencpu package, which basically requires the creation of an R package and the use of the opencpu :: ocpu_start_app ('package') function to run the API.
So I created an R package consisting of two basic content functions that are in my current shiny application. The first makes a filter in the database according to parameters, which worked perfectly when doing POST request using the 'curl' function in the terminal; and the second refers to a histogram created in the highcharter package, as function below.
function (data = lic, ano = ano, valor_max = valor, dir = ".")
{
require(tidyr)
valor_graf <- filter_data_ano(data = data, ano = ano)
valor_graf <- dplyr::filter(valor_graf, valor <= valor_max)
if (nrow(valor_graf) != 0) {
hc <- highcharter::hchart(hist(valor_graf$valor, plot = FALSE),
color = "#bcbddc", name = FALSE) %>% highcharter::hc_xAxis(title = list(text = "Valor")) %>%
highcharter::hc_yAxis(title = list(text = "Quantidade")) %>%
highcharter::hc_legend(enabled = FALSE)
htmlwidgets::saveWidget(hc, paste(dir, "/valor_graf.html", sep = ""), selfcontained = FALSE)
}
else {
hc <- highcharter::highchart() %>% highcharter::hc_chart(marginTop = 80,
marginBottom = 50) %>% highcharter::hc_add_series(data = c(NA,
NA), showInLegend = F) %>% highcharter::hc_xAxis(min = 1,
max = 50) %>% highcharter::hc_yAxis(min = 1, max = 50)
htmlwidgets::saveWidget(hc, paste(dir, "/valor_graf.html",
sep = ""), selfcontained = FALSE)
}
}
Regarding the creation of this graphic, note that I had to use the htmlwidgets :: saveWidget () function to save the graphic in html extension, since it is dynamic. I was able to make a POST request using the 'curl' function on the terminal. The 'graph.html' file has been placed in a temporary API folder.
Also, through internet searches, I realized that for maps created in the leaflet package, for example, I should also use the htmlwidgets :: saveWidget () function to save it in .html.
I say this because you mentioned that it would be more complicated to use the API for graphs and interactive maps. So, according to my report above, do you think the API via opencpu is inappropriate for this, ie create a .html file with interactive charts and maps? I've been able to do it, but I do not know how easy it will be to use it when you apply through another language.
Thank you!