Я пишу код ниже, для которого это простое приложение для отображения кривых из файлов данных, созданных лабораторным оборудованием. Мне нужно объединить все файлы в выбранной папке, выполнить простую обработку данных и затем отобразить наложенные кривые.
Я получаю ошибку cannot open the connection
в области графика при попытке загрузить файлы. Я также пытался отобразить multiple_datatable
в datatableoutput
, но я получаю точно такую же ошибку.
Редактировать: Спасибо за ваш комментарий, вот более простая версия с только необходимыми код.
Некоторые данные
файл 1
c("#FILE: ;Grofillex 1000°C 10K 5' air _ AW70ter.ngb-ss1",
"#FORMAT: ;NETZSCH5 ",
"#IDENTITY: ;STA2020-018 ",
"#DECIMAL: ;POINT ",
"#SEPARATOR: ;SEMICOLON ",
"#MTYPE: ;DSC ",
"#INSTRUMENT: ;NETZSCH STA 449F1 ",
"#PROJECT: ;Grosfillex ",
"#DATE/TIME: ;29/01/2020 11:04:11 ",
"#CORR. FILE: ; ",
"#LABORATORY: ;LFM ",
"#OPERATOR: ;AM ",
"#REMARK: ; ",
"#SAMPLE: ;Grosfillex AW70 ter ",
"#SAMPLE MASS /mg: ;23.99 ",
"#MATERIAL: ; ",
"#REFERENCE: ;Référence ",
"#REFERENCE MASS /mg: ;0 ",
"#TYPE OF CRUCIBLE: ;DSC/TG pan Al2O3 ",
"#SAMPLE CRUCIBLE MASS /mg: ;216.98 ",
"#REFERENCE CRUCIBLE MASS /mg:;214 ",
"#CORR. CODE: ;000 ",
"#EXO: ;+1 ",
"#RANGE: ;20....1000/-40.0....10.0K/min ",
"#SEGMENT: ;S1-4/4 ",
"", "##Temp./°C;Time/min;DSC/(uV/mg);Mass/%;Gas Flow(purge1)/(ml/min);Gas Flow(protective)/(ml/min);Sensit./(uV/mW);Segment",
" 20.72500;0.0000e+000;-1.7173e-003;100.00000;80.00000;20.00000;1.00000;1",
" 20.74233;5.0000e-002;-1.6219e-003;100.27209;80.00000;20.00000;1.00000;1",
" 20.74440; 0.10000;-1.5583e-003; 99.84077;80.00000;20.00000;1.00000;1",
" 20.74786; 0.15000;-1.5583e-003; 99.67799;80.00000;20.00000;1.00000;1",
" 20.74822; 0.20000;-1.5265e-003; 99.54200;80.00000;20.00000;1.00000;1",
" 20.74882; 0.25000;-1.5583e-003; 99.43706;80.00000;20.00000;1.00000;1",
" 20.74938; 0.30000;-1.4629e-003; 99.34389;80.00000;20.00000;1.00000;1",
" 20.75073; 0.35000;-1.3357e-003; 99.27095;80.00000;20.00000;1.00000;1",
" 20.75147; 0.40000;-1.4629e-003; 99.20383;80.00000;20.00000;1.00000;1",
" 20.75376; 0.45000;-1.5901e-003; 99.15830;80.00000;20.00000;1.00000;1",
" 20.75500; 0.50000;-1.6537e-003; 99.12828;80.00000;20.00000;1.00000;1",
" 20.75571; 0.55000;-1.5901e-003; 99.11922;80.00000;20.00000;1.00000;1",
" 20.75788; 0.60000;-1.6855e-003; 99.10786;80.00000;20.00000;1.00000;1",
" 20.75924; 0.65000;-1.9717e-003; 99.08993;80.00000;20.00000;1.00000;1",
" 20.76088; 0.70000;-2.1308e-003; 99.07180;80.00000;20.00000;1.00000;1",
" 20.76088; 0.75000;-2.2580e-003; 99.05336;80.00000;20.00000;1.00000;1",
" 20.76212; 0.80000;-2.0990e-003; 99.03449;80.00000;20.00000;1.00000;1",
" 20.76312; 0.85000;-2.2262e-003; 99.01772;80.00000;20.00000;1.00000;1",
" 20.76624; 0.90000;-2.2580e-003; 99.00156;80.00000;20.00000;1.00000;1",
" 20.76641; 0.95000;-2.3534e-003; 98.98437;80.00000;20.00000;1.00000;1",
" 20.76782; 1.00000;-2.4170e-003; 98.96738;80.00000;20.00000;1.00000;1",
" 20.77018; 1.05000;-2.3534e-003; 98.94946;80.00000;20.00000;1.00000;1",
" 20.77147; 1.10000;-2.4170e-003; 98.93206;80.00000;20.00000;1.00000;1"
)
файл 2
c("#FILE: ;Grofillex 1000°C 10K 5' air _ F1B.ngb-ss1",
"#FORMAT: ;NETZSCH5 ",
"#IDENTITY: ;STA2020-005 ",
"#DECIMAL: ;POINT ",
"#SEPARATOR: ;SEMICOLON ",
"#MTYPE: ;DSC ",
"#INSTRUMENT: ;NETZSCH STA 449F1 ",
"#PROJECT: ;Grosfillex ",
"#DATE/TIME: ;14/01/2020 16:33:22 ",
"#CORR. FILE: ; ",
"#LABORATORY: ;LFM ",
"#OPERATOR: ;AM ",
"#REMARK: ; ",
"#SAMPLE: ;Grosfillex F1B ",
"#SAMPLE MASS /mg: ;23.30 ",
"#MATERIAL: ; ",
"#REFERENCE: ;Référence ",
"#REFERENCE MASS /mg: ;0 ",
"#TYPE OF CRUCIBLE: ;DSC/TG pan Al2O3 ",
"#SAMPLE CRUCIBLE MASS /mg: ;216.31 ",
"#REFERENCE CRUCIBLE MASS /mg:;214 ",
"#CORR. CODE: ;000 ",
"#EXO: ;+1 ",
"#RANGE: ;20....1000/-40.0....10.0K/min ",
"#SEGMENT: ;S1-4/4 ",
"", "##Temp./°C;Time/min;DSC/(uV/mg);Mass/%;Gas Flow(purge1)/(ml/min);Gas Flow(protective)/(ml/min);Sensit./(uV/mW);Segment",
" 22.27000;0.0000e+000; 1.4735e-003;100.00000;80.00000;20.00000;1.00000;1",
" 22.25833;5.0000e-002; 1.2770e-003;100.39850;80.00000;20.00000;1.00000;1",
" 22.26100; 0.10000; 9.4958e-004; 99.79292;80.00000;20.00000;1.00000;1",
" 22.26100; 0.15000; 8.8409e-004; 99.62661;80.00000;20.00000;1.00000;1",
" 22.26267; 0.20000; 8.1860e-004; 99.50172;80.00000;20.00000;1.00000;1",
" 22.26427; 0.25000; 6.8763e-004; 99.38573;80.00000;20.00000;1.00000;1",
" 22.26492; 0.30000; 5.5665e-004; 99.29442;80.00000;20.00000;1.00000;1",
" 22.26620; 0.35000; 4.9116e-004; 99.22543;80.00000;20.00000;1.00000;1",
" 22.26606; 0.40000; 3.9293e-004; 99.14893;80.00000;20.00000;1.00000;1",
" 22.26624; 0.45000; 2.6195e-004; 99.11513;80.00000;20.00000;1.00000;1",
" 22.26700; 0.50000; 2.2921e-004; 99.07629;80.00000;20.00000;1.00000;1",
" 22.26806; 0.55000;-6.5488e-005; 99.02597;80.00000;20.00000;1.00000;1",
" 22.26859; 0.60000;-6.5488e-005; 99.01266;80.00000;20.00000;1.00000;1",
" 22.26847; 0.65000;-3.2744e-005; 98.99828;80.00000;20.00000;1.00000;1",
" 22.26924; 0.70000;-3.6019e-004; 98.98938;80.00000;20.00000;1.00000;1",
" 22.27012; 0.75000;-2.9470e-004; 98.97006;80.00000;20.00000;1.00000;1",
" 22.26982; 0.80000;-4.5842e-004; 98.94635;80.00000;20.00000;1.00000;1",
" 22.27241; 0.85000;-7.2037e-004; 98.91567;80.00000;20.00000;1.00000;1",
" 22.27235; 0.90000;-6.8763e-004; 98.89496;80.00000;20.00000;1.00000;1",
" 22.27435; 0.95000;-8.8409e-004; 98.87800;80.00000;20.00000;1.00000;1",
" 22.27600; 1.00000;-9.8233e-004; 98.86030;80.00000;20.00000;1.00000;1",
" 22.27671; 1.05000;-9.1684e-004; 98.83444;80.00000;20.00000;1.00000;1",
" 22.27759; 1.10000;-1.1788e-003; 98.81330;80.00000;20.00000;1.00000;1"
)
и код
library(shiny)
library(xlsx)
library(readxl)
library(dplyr)
library(ggplot2)
library(reshape2)
library(viridis)
library(zoo)
library(lubridate)
library(shinyFiles)
library(htmltools)
ui <- fluidPage(
navbarPage("ATG-DSC App",
tabPanel("Multiple file comparison",
pageWithSidebar(
headerPanel(""),
sidebarPanel(width = 2,shinyDirButton('directory', 'Folder select', 'Please select a folder')),
mainPanel(fluidRow(
column(12,
dataTableOutput("multiple_datatable"),
uiOutput("plot.ui2"))))))))
server = function(input, output, session){
volumes <- getVolumes()
shinyDirChoose(input, 'directory', roots=volumes, session=session)
path1 <- reactive({
return(print(parseDirPath(volumes, input$directory)))
})
filenames <- eventReactive(input$directory, {
file.names <- dir(path1(), pattern =".txt")
return(file.names)
})
#data reading
dataset_multiple <- eventReactive(input$directory, {
out.file<-""
file.names <- dir(path1(), pattern =".txt")
for(i in 1:length(file.names)){
lines <- readLines(file.names[i])
column_names <- gsub("#",'',unlist(strsplit(lines[27],";")))
header <- lines[1:26]
lines <- lines[seq(27,length(lines),5)]
col <- length(column_names)
data <- as.data.frame(matrix(unlist(strsplit(lines,";")),ncol=col,byrow=T))
data <- data[2:nrow(data),]
colnames(data) <- column_names
for (i in 1:ncol(data)){
data[,i] <- as.numeric(gsub(",",".",as.character(data[,i])))
}
data$sample <- unlist(strsplit(header,";"))[28]
out.file <- rbind(out.file, data)
for (i in 1:(ncol(out.file)-1)){
out.file[,i] <- as.numeric(gsub(",",".",as.character(out.file[,i])))
}
}
out.file$`Sensit./(uV/mW)` <- NULL
out.file$`Time/min` <- NULL
out.file <- out.file[complete.cases(out.file),]
out.file <- out.file[out.file$Segment==2,]
out.file$Segment <- NULL
out.file$`Gas Flow(protective)/(ml/min)` <- NULL
out.file$`Gas Flow(purge1)/(ml/min)` <- NULL
names(out.file) <- c("Temp", "DSC", "Mass", "Sample")
return(out.files)
})
output$multiple_plot <- renderPlot({
multiple_data <- dataset_multiple()
multiple_data_melt <- melt(multiple_data, id=c("Temp","Sample"))
col_pal <- color_palette()
g <- ggplot(multiple_data_melt,aes(multiple_data_melt$Temp,multiple_data_melt$value, group=sample, color=sample))
+ geom_point()
+ facet_grid(variable~.,scales = "free_y")
print(g)
})
output$multiple_datatable <- eventReactive(input$directory, {
multiple_data <- dataset_multiple()
multiple_data_melt <- melt(multiple_data, id=c("Temp","Sample"))
return(head(multiple_data_melt))
})
output$plot.ui2 <- renderUI({
plotOutput("multiple_plot")
})
}
shinyApp(ui = ui, server = server, options = list(launch.browser=TRUE))
Может кто-нибудь помочь?