#Текст программы на языке программирования R. #Файлы с выборкой не вошли в 10 предложенных мб по правилам заявки. #Если необходимо предоставить выборку, просьба написать по почте maska0218@gmail.com library(shiny) library(plotly) if(Sys.getenv('SHINY_PORT') == "") options(shiny.maxRequestSize=10000*1024^2) ui <- fluidPage( sidebarLayout( sidebarPanel( fileInput("nn", "Choose CSV file", multiple = TRUE, accept = c("text/csv", "text/comma-separated-values,text/plain", ".csv")), sliderInput("slaedr1", "spar", min = 0, max = 1, value = c(0.3)), uiOutput("ui"), uiOutput("uui") ), mainPanel( tabsetPanel(type = "tabs", tabPanel("РћРґРёРЅ параметр для выбранного пациента", plotlyOutput("Plot1")), tabPanel("R5 для РѕРґРЅРѕРіРѕ человека", plotlyOutput("Plot1a")), tabPanel("Выбранный параметр для РѕРґРЅРѕРіРѕ пациента", plotlyOutput("Plot11")), tabPanel("Изменение сопротивления R5", plotlyOutput("Plot111")), tabPanel("R5 Рё изменение сопротивления R5", plotlyOutput("Plot111a")) ) ) ) ) server <- function(input, output) { n <- reactive({ read.csv(input$nn$datapath, dec = ',',header = TRUE, sep = ';', stringsAsFactors = FALSE) }) output$ui <- renderUI({ if(!is.null(input$nn)) { selectInput("patients", "Patients", choices = unique(n()$'Name'), multiple = TRUE, selected = c('Рђ***РёРЅ РЎ***ан')) } }) output$uui <- renderUI({ if(!is.null(input$nn)) { selectInput("parameters", "Parameters", choices = names(n()), multiple = TRUE, selected = c('R5_L.L.', 'R5_R.L.') ) } }) output$'Plot1' <- renderPlotly({ if(!is.null(input$nn)) { n1 = n() p <- plot_ly() for (param in input$parameters) { y1 = n1[n1[,'Name'] == input$patients, param] p <- add_trace(p, x = seq(1, nrow(n1[n1$'Name' == input$patients,]), 1)*2, y = (y1-y1[1])/y1[1]*100, type = "scatter", mode = "markers", name = param) } for (param in input$parameters) { X = seq(1, nrow(n1[n1$'Name' == input$patients,]), 1) Y = n1[n1[,'Name'] == input$patients, param] ad <- smooth.spline(Y, spar = input$slaedr1) nad = predict(ad, X)$y p <- add_trace(p, x = X*2, y = (nad-nad[1])/nad[1]*100, type = "scatter", mode = "lines", name = param) } p <- layout(p, title = list(title = "РћРґРёРЅ параметр для выбранного пациента"), xaxis = list(title = "Time (sec)"), yaxis = list(title = "Resistance (mOm)")) p } else plot_ly() }) output$'Plot1a' <- renderPlotly({ if(!is.null(input$nn)) { n1 = n() p <- plot_ly() for (nnn in input$patients) { y1 = n1[n1[,'Name'] == nnn, 'R5_L.L.'] y2 = n1[n1[,'Name'] == nnn, 'R5_R.L.'] p <- add_trace(p, x = seq(1, nrow(n1[n1$'Name' == nnn,]), 1)*2, y = (y1-y1[1])/y1[1]*1000, type = "scatter", mode = "markers", name = "") p <- add_trace(p, x = seq(1, nrow(n1[n1$'Name' == nnn,]), 1)*2, y = (y2-y2[1])/y2[1]*1000, type = "scatter", mode = "markers", name = "") X = seq(1, nrow(n1[n1$'Name' == nnn,]), 1) Y1 = n1[n1[,'Name'] == nnn, 'R5_L.L.'] Y2 = n1[n1[,'Name'] == nnn, 'R5_R.L.'] ad1 <- smooth.spline(Y1, spar = input$slaedr1) ad2 <- smooth.spline(Y2, spar = input$slaedr1) nad1 = predict(ad1, X)$y nad2 = predict(ad2, X)$y p <- add_trace(p, x = X*2, y = (nad1-nad1[1])/nad1[1]*1000, type = "scatter", mode = "lines", name = "") p <- add_trace(p, x = X*2, y = (nad2-nad2[1])/nad2[1]*1000, type = "scatter", mode = "lines", name = "") } p <- layout(p, title = list(title = "R5 для РѕРґРЅРѕРіРѕ человека"), xaxis = list(title = "Time (sec)"), yaxis = list(title = "Resistance (mOm)")) p } else plot_ly() }) output$'Plot111' <- renderPlotly({ if(!is.null(input$nn)) { n1 = n() p <- plot_ly() for (nnn in input$patients) { deltn = n1[n1[,'Name'] == nnn, 'R5_L.L.'] delta = deltn[1] X = seq(1, nrow(n1[n1$'Name' == nnn,]), 1) Y1 = n1[n1[,'Name'] == nnn, 'R5_L.L.'] Y2 = n1[n1[,'Name'] == nnn, 'R5_R.L.'] ad1 <- smooth.spline(Y1, spar = input$slaedr1) ad2 <- smooth.spline(Y2, spar = input$slaedr1) nad1 = predict(ad1, X)$y nad2 = predict(ad2, X)$y sd1 = (nad2-nad2[1])/nad2[1]-(nad1-nad1[1])/nad1[1] yy = n1[n1[,'Name'] == nnn, 'R5_L.L.'] yy1 = n1[n1[,'Name'] == nnn, 'R5_R.L.'] y1 = (yy1-yy1[1])/yy1[1]-(yy-yy[1])/yy[1] p <- add_trace(p, x = X*2, y = y1*1000, type = "scatter", mode = "markers", name = "") p <- add_trace(p, x = X*2, y = sd1*1000, type = "scatter", mode = "lines", name = "") } p <- layout(p, title = list(title = ""), xaxis = list(title = "Time (sec)"), yaxis = list(title = "Resistance (mOm)")) p } else plot_ly() }) output$'Plot111a' <- renderPlotly({ if(!is.null(input$nn)) { n1 = n() p <- plot_ly() for (nnn in input$patients) { deltn = n1[n1[,'Name'] == nnn, 'R5_L.L.'] delta = deltn[1] X = seq(1, nrow(n1[n1$'Name' == nnn,]), 1) Y1 = n1[n1[,'Name'] == nnn, 'R5_L.L.'] Y2 = n1[n1[,'Name'] == nnn, 'R5_R.L.'] ad1 <- smooth.spline(Y1, spar = input$slaedr1) ad2 <- smooth.spline(Y2, spar = input$slaedr1) nad1 = predict(ad1, X)$y nad2 = predict(ad2, X)$y sd1 = (nad2-nad2[1])/nad2[1]-(nad1-nad1[1])/nad1[1] yy = n1[n1[,'Name'] == nnn, 'R5_L.L.'] yy1 = n1[n1[,'Name'] == nnn, 'R5_R.L.'] y1 = (yy1-yy1[1])/yy1[1]-(yy-yy[1])/yy[1] p <- add_trace(p, x = X*2, y = y1*1000, type = "scatter", mode = "markers", name = "") p <- add_trace(p, x = X*2, y = sd1*1000, type = "scatter", mode = "lines", name = "") } y1 = n1[n1[,'Name'] == input$patients, 'R5_L.L.'] y2 = n1[n1[,'Name'] == input$patients, 'R5_R.L.'] p <- add_trace(p, x = seq(1, nrow(n1[n1$'Name' == input$patients,]), 1)*2, y = (y1-y1[1])/y1[1]*1000, type = "scatter", mode = "markers", name = "R5 L.L.") p <- add_trace(p, x = seq(1, nrow(n1[n1$'Name' == input$patients,]), 1)*2, y = (y2-y2[1])/y2[1]*1000, type = "scatter", mode = "markers", name = "R5 R.L.") X = seq(1, nrow(n1[n1$'Name' == input$patients,]), 1) Y1 = n1[n1[,'Name'] == input$patients, 'R5_L.L.'] Y2 = n1[n1[,'Name'] == input$patients, 'R5_R.L.'] ad1 <- smooth.spline(Y1, spar = input$slaedr1) ad2 <- smooth.spline(Y2, spar = input$slaedr1) nad1 = predict(ad1, X)$y nad2 = predict(ad2, X)$y p <- add_trace(p, x = X*2, y = (nad1-nad1[1])/nad1[1]*1000, type = "scatter", mode = "lines", name = "R5 L.L.") p <- add_trace(p, x = X*2, y = (nad2-nad2[1])/nad2[1]*1000, type = "scatter", mode = "lines", name = "R5 R.L.") p <- layout(p, title = list(title = ""), xaxis = list(title = "Time (sec)"), yaxis = list(title = "Resistance (mOm)")) p } else plot_ly() }) output$'Plot11' <- renderPlotly({ if(!is.null(input$nn)) { n1 = n() p <- plot_ly() for (nnn in input$patients) { X = seq(1, nrow(n1[n1$'Name' == nnn,]), 1) Y = n1[n1$'Name' == nnn, input$parameters] ad <- smooth.spline(Y, spar = input$slaedr1) nad = predict(ad, X)$y y1 = n1[n1$'Name' == nnn, input$parameters] p <- add_trace(p, x = seq(1, nrow(n1[n1$'Name' == nnn,]), 1)*2, y = (y1-y1[1])/y1[1]*1000, type = "scatter", mode = "markers", name = "") p <- add_trace(p, x = X*2, y = (nad-nad[1])/nad[1]*1000, type = "scatter", mode = "lines", name = "") } p <- layout(p, title = list(title = "Выбранный параметр для РѕРґРЅРѕРіРѕ пациента"), xaxis = list(title = "Time (sec)"), yaxis = list(title = "Resistance (mOm)")) p } else plot_ly() }) } shinyApp(ui,server)