所以这是我的基本应用程序,它改写了我的一部分,它仍然似乎并不奏效。
library(shiny)
library(shinythemes)
ui <- fluidPage(theme = shinytheme("sandstone"),
navbarPage(title = "Project Methylation",
tabPanel(title = "Main",
wellPanel(
column(4,
sliderInput("lowMethRangeS", "Low methylation range", min=0, max=1, value=c(0,0.4), step=0.01)),
column(4,
sliderInput("medMethRangeS", "Medium methylation range", min=0, max=1, value=c(0.4,0.6), step=0.01)),
column(4,
sliderInput("highMethRangeS", "High methylation range", min = 0, max = 1, value = c(0.6,1), step=0.01)))),
fluidRow(
verbatimTextOutput("test"),
textOutput("test2")
)
)
)
)
server <- function(input, output, session) {
#This chunk of the code will connect the three sliders together to update automatically
observe({
val1S <- input$lowMethRangeS
val2S <- input$medMethRangeS
updateSliderInput(session, "medMethRangeS", value = c(val1S[2],val2S[2]), min = 0, max = 1, step = 0.01)
updateSliderInput(session, "highMethRangeS", value = c(val2S[2],1), min = 0, max = 1, step = 0.01)
})
observe({
val1P <- input$lowMethRangeP
val2P <- input$medMethRangeP
updateSliderInput(session, "medMethRangeP", value = c(val1P[2],val2P[2]), min = 0, max = 1, step = 0.01)
updateSliderInput(session, "highMethRangeP", value = c(val2P[2],1), min = 0, max = 1, step = 0.01)
})
#The next line is just to read the file
rawFileCoding <- read.csv(file = "coding.csv", header = TRUE, sep = ",")
#This is the part I have problem with!!!
counters <- reactiveValues(
CBLcounter = 0,
CPLcounter = 0,
CCLcounter = 0,
CNLcounter = 0
)
for(i in 1:length(rawFileCoding$BEN)){
if(rawFileCoding$BEN[i]>=input$lowMethRangeS[1] && rawFileCoding$BEN[i] <= input$lowMethRangeS[2]){
counters$CBLcounter <- isolate(counters$CBLcounter) + 1
counters$CPLcounter <- isolate(counters$CPLcounter) + 1
counters$CCLcounter <- isolate(counters$CCLcounter) + 1
counters$CNLcounter <- isolate(counters$CNLcounter) + 1
}
}
#I just added these two ways to just make sure the loop has worked
output$test <- renderPrint ({counters$CBLcounter})
output$test2 <- renderText ({counters$CBLcounter})
}
shinyApp(ui = ui, server = server)
@Geovany请看看这个。提前谢谢你的帮助 – sajjad6al