我想让我的server.R文件在启动时加载二进制矩阵的csv文件。
library(shiny)
server <- function(input, output) {
#this aint loading
df <- read.csv("starGraphAdjMatrix.csv",
header = TRUE,
sep = ",",
quote='"')
#output$loadedMat -> output$loadedMat
output$loadedMat <- renderTable({
# input$file1 will be NULL initially. After the user selects
# and uploads a file, head of that data file by default,
# or all rows if selected, will be shown.
#falsy value if empty
req(input$file1)
# when reading semicolon separated files,
# having a comma separator causes `read.csv` to error
tryCatch(
{
df <- read.csv(input$file1$datapath,
header = TRUE,
sep = ",",
quote='"')
df$X <- NULL
},
error = function(e) {
# return a safeError if a parsing error occurs
stop(safeError(e))
}
)
return(df)
},
rownames = FALSE, colnames = FALSE)
}
完整代码包括ui.R和starGraphAdjMatrix: https://github.com/andandandand/fixCSVLoad
答案 0 :(得分:1)
不确定这是否是你所追求的:
library(shiny)
server <- function(input, output) {
output$contents <- renderTable({
if (is.null(input$file1$datapath)) {
dpath <- "starGraphAdjMatrix.csv"
} else {
dpath <- input$file1$datapath
}
read.csv(dpath)
}, rownames = FALSE, colnames = FALSE)
}