Does anyone know how to save the data from the my data frame then export to csv file in the same folder location where the user inputs the file.
Here's my program structure:
- User will be prompt for folder location then read Pajek(.net) file
- Calculate the degree of each vertex which is sorted by the degree of each vertex, highest degree is at the top and lowest at the bottom.then show in a data frame.
- Output a CSV file in the same folder location,
Here's what I've done so far:
ui.R
library(igraph)
options(shiny.maxRequestSize=-1)
shinyUI(fluidPage(
titlePanel("Finding most influential vertex in a network"),
sidebarLayout(
sidebarPanel(
fileInput("graph", label = h4("Pajek file")),
downloadButton("downloadData", "Download")
),
mainPanel( uiOutput("tb")
)
)
))
server.R
library(igraph)
options(shiny.maxRequestSize=-1)
shinyServer(
function(input, output) {
filedata <- reactive({
inFile = input$graph
if (!is.null(inFile))
read.graph(file=inFile$datapath, format="pajek")
})
Data <- reactive({
df <- filedata()
vorder <-order(degree(df), decreasing=TRUE)
DF <- data.frame(ID=as.numeric(V(df)[vorder]), degree=degree(df)[vorder])
})
output$tb <- renderUI({
if(is.null(filedata()))
h2("Please select Pajek file..")
else
tabsetPanel(type = "tabs",
tabPanel("Table", tableOutput("view")) )
}
)
output$view <- renderTable({
Data()
})
output$downloadData <- downloadHandler(
filename = function() {
paste("degree", '.csv', sep='')
},
content = function(file) {
write.csv(Data(), file)
}
)
})
However, the file did not save. Does anyone know how to fix this?