shiny - How to display flowchart created using R Diagram library in an Rshiny app? -
i trying display flowchart using r diagram
library in rshiny app similar 1 shown below. tried plotoutput()
not able display flowchart in rshiny app tab. can please enlighten me on missing here?
library(diagram) library(shape) par(mar = c(1, 1, 1, 1)) openplotmat() elpos <- coordinates (c(1, 1, 2, 4)) fromto <- matrix(ncol = 2, byrow = true, data = c(1, 2, 2, 3, 2, 4, 4, 7, 4, 8,3,5,3,6)) nr <- nrow(fromto) arrpos <- matrix(ncol = 2, nrow = nr) (i in 1:nr) arrpos[i, ] <- straightarrow (to = elpos[fromto[i, 2], ], = elpos[fromto[i, 1], ], lwd = 2, arr.pos = 0.6, arr.length = 0.5) textellipse(elpos[1,], 0.1, lab = "start", box.col = "green", shadow.col = "darkgreen", shadow.size = 0.005, cex = 1.5) textrect (elpos[2,], 0.15, 0.05,lab = "found term?", box.col = "grey", shadow.col = "darkblue", shadow.size = 0.005, cex = 1.5) textrect (elpos[4,], 0.15, 0.05,lab = "related?", box.col = "grey", shadow.col = "darkblue", shadow.size = 0.005, cex = 1.5) textellipse(elpos[3,], 0.1, 0.1, lab = c("other","term"), box.col = "orange", shadow.col = "red", shadow.size = 0.005, cex = 1.5) textellipse(elpos[7,], 0.1, 0.1, lab = c("make","a link"),box.col = "orange", shadow.col = "red", shadow.size = 0.005, cex = 1.5) textellipse(elpos[8,], 0.1, 0.1, lab = c("new","article"),box.col = "orange", shadow.col = "red", shadow.size = 0.005, cex = 1.5) textellipse(elpos[5,], 0.1, 0.1, lab = c("make","a link"),box.col = "orange", shadow.col = "red", shadow.size = 0.005, cex = 1.5) textellipse(elpos[6,], 0.1, 0.1, lab = c("new","article"),box.col = "orange", shadow.col = "red", shadow.size = 0.005, cex = 1.5) # dd <- c(0.0, 0.025) text(arrpos[2, 1] + 0.05, arrpos[2, 2], "yes") text(arrpos[3, 1] - 0.05, arrpos[3, 2], "no") text(arrpos[4, 1] + 0.05, arrpos[4, 2] + 0.05, "yes") text(arrpos[5, 1] - 0.05, arrpos[5, 2] + 0.05, "no") #
did use plotoutput
in ui, , renderplot
in server? tried following, , works me.
#
# shiny web application. can run application clicking # 'run app' button above. # # find out more building applications shiny here: # # http://shiny.rstudio.com/ # library(shiny) library(diagram) library(shape) # define ui application draws histogram ui <- fluidpage( # show plot of generated distribution mainpanel( plotoutput("testplot") ) ) # define server logic required draw histogram server <- function(input, output) { # output$testplot <- renderplot({ par(mar = c(1, 1, 1, 1)) openplotmat() elpos <- coordinates (c(1, 1, 2, 4)) fromto <- matrix(ncol = 2, byrow = true, data = c(1, 2, 2, 3, 2, 4, 4, 7, 4, 8,3,5,3,6)) nr <- nrow(fromto) arrpos <- matrix(ncol = 2, nrow = nr) (i in 1:nr) arrpos[i, ] <- straightarrow (to = elpos[fromto[i, 2], ], = elpos[fromto[i, 1], ], lwd = 2, arr.pos = 0.6, arr.length = 0.5) textellipse(elpos[1,], 0.1, lab = "start", box.col = "green", shadow.col = "darkgreen", shadow.size = 0.005, cex = 1.5) textrect (elpos[2,], 0.15, 0.05,lab = "found term?", box.col = "grey", shadow.col = "darkblue", shadow.size = 0.005, cex = 1.5) textrect (elpos[4,], 0.15, 0.05,lab = "related?", box.col = "grey", shadow.col = "darkblue", shadow.size = 0.005, cex = 1.5) textellipse(elpos[3,], 0.1, 0.1, lab = c("other","term"), box.col = "orange", shadow.col = "red", shadow.size = 0.005, cex = 1.5) textellipse(elpos[7,], 0.1, 0.1, lab = c("make","a link"),box.col = "orange", shadow.col = "red", shadow.size = 0.005, cex = 1.5) textellipse(elpos[8,], 0.1, 0.1, lab = c("new","article"),box.col = "orange", shadow.col = "red", shadow.size = 0.005, cex = 1.5) textellipse(elpos[5,], 0.1, 0.1, lab = c("make","a link"),box.col = "orange", shadow.col = "red", shadow.size = 0.005, cex = 1.5) textellipse(elpos[6,], 0.1, 0.1, lab = c("new","article"),box.col = "orange", shadow.col = "red", shadow.size = 0.005, cex = 1.5) # dd <- c(0.0, 0.025) text(arrpos[2, 1] + 0.05, arrpos[2, 2], "yes") text(arrpos[3, 1] - 0.05, arrpos[3, 2], "no") text(arrpos[4, 1] + 0.05, arrpos[4, 2] + 0.05, "yes") text(arrpos[5, 1] - 0.05, arrpos[5, 2] + 0.05, "no") }) } # run application shinyapp(ui = ui, server = server)
Comments
Post a Comment