I found this regarding getting multiple outputs from a reactive script, but this still assumes that both will be used in the same object which is ultimately output. However, even if I get this working, I'm concerned that using these outputs from 2 different renderSomething({}) functions will mean my reactive script has to run twice each time.
My original code is quite lengthy, so I'll just include where I'm having an issue:
#main function
server<-function(input, output){
main<-reactive({
#a bunch of stuff producing what it needed for output
if(nglabels>0){
#return number of labelings:
outputText<-paste("Graph has",nglabels,"graceful labelings",sep=" ",collapse=NULL)
#return FedgeLabel for graph:
outputGraph<-graph_from_adjacency_matrix(FedgeLabel,mode=c("undirected"),weighted=TRUE,add.colnames=FvertexLabel,add.rownames=FvertexLabel)
} else {
outputText<-"No graceful labels"
#return imported graph as-is
outputGraph<-graph_from_adjacency_matrix(mat,mode=c("undirected"))
}
#reactive in R only allows 1 output, so we need to make a list of these:
outputList<-list(outputText=outputText,outputGraph=outputGraph)
return(outputList)
})
#outputting what was calculated
output$txt<-renderText({
getOutput<-main()
getOutput$outputText})
output$Graph<-renderPlot({
getOutput<-main()
plot(getOutput$outputGraph)})
} #this is the end brace from the server function
Of course, as of right now, neither is returning correctly, but given computation times could get large depending on input, I would much rather find an elegant way to get my outputs out of just the one reactive function.
mainon the second line.observe(print(str(main())))outside of thereactive()calls and run the app, what does it say in the console?