I am using the latest version of R, plotly and shiny. I have used the orcaa command to save the plotly images in the past and has worked for me. However, when trying to save the plotly charts in shiny using orca does not seem to be working.
The best I could do is either save the chart and no display or display the chart and not get it saved using the orca function. Is there a fix to this. I am using Shiny modules in my code.
Any help is appreciated. The part of the code is as follows (with some comments in it).
plotting_module_UI <- function(id) {
message("Plotting the charts in progress now")
plotlyOutput(ns("s"), height = "750px", width = "1800px"),
fluidRow(
column(
2,
downloadButton(outputId = ns("downloadchartdatabut"), label = "Download raw data set for this chart")) # button to download the raw data in a csv file
)
)
}
plotting_module <- function(input, output, session, cn){
### some more data manipulation and data massaging
chart <- reactive({
plot_ly(newdata, x = eval(parse(text = paste("newdata$",input$s_xaxis,sep = ""))), y = newdata$fValue, height = 720, width = 1200, type = "box",
color = eval(parse(text = paste("newdata$",input$s_groups,sep = ""))), pointpos = 0, boxpoints = 'all') %>%
layout(yaxis = c(list(title = paste(unique(newdata$vcStructure)," (",unique(newdata$vcUnits),") ", sep = "" ), range = range_ip()), a1),
margin = list(l = 100)) %>%
layout(boxmode = "group") %>%
layout(xaxis = c(list(title = input$s_xaxis, tickangle = 90), a1)) %>%
layout(shapes = list(hline(unique(newdata$fLowerSpec)),hline(unique(newdata$fUpperSpec)))) %>%
layout(title = paste(newdata$vcVendor, newdata$vcProcess, newdata$vcStructure, sep = " / "))
# orca(chart(), paste(unique(newdata$vcStructure)[1],".png", sep = "")) # orca function under the reactive function does not show any output but saves the chart directly which is not helpful as we need to change the charts based on some buttons on the shiny page.
}
})
output$s <- renderPlotly(chart())
reactive({orca(chart(), paste(unique(newdata$vcStructure)[1],".png", sep = ""))}) # without the reactive function, R gives and error that function like this should be in reactive environment. However, even with reactive, no image is being saved.
}
app = shinyApp(
ui = fluidPage(
#### display of some tables and buttons
fluidRow(
lapply(1:length(unique(getData$vcStructure)), function(i) plotting_module_UI(unique(getData$vcStructure)[i])))
),
server = function(input, output, session) {
##### some more data code for display of tables etc.
lapply(1:5,
function(i)
callModule(plotting_module, unique(getData$vcStructure)[i], unique(getData$vcStructure)[i]))
session$onSessionEnded(function() {
stopApp()
})
})