EDIT 끝 부분의 재현 가능한 예입니다.observeEvent()의 중첩 된 observeEvent()가 너무 자주 실행됩니다.
here과 비슷한 문제가 발견되었지만 reactive()
을 사용하면 문제가 해결되지 않습니다.
사용자가 FileInput
으로 파일을 업로드 할 수있는 앱을 개발 중입니다. 지금까지는 FASTQ 및 CSV 파일을 처리 할 수 있습니다 (여기서 CSV에 초점). 업로드 된 모든 파일은 RData로 저장되며 다시로드 된 selectinput
에서 선택할 수 있습니다. 이 selectinput
은 기본적으로 모든 것을 실행합니다. 평가 된 후에 CSV를 표시하기 위해 반응적인 UI를 트리거합니다. 또한 새 파일을 선택한 다음 행을 선택해도 이전 파일의 행을 인쇄 할 때 그 파일을 인쇄 할 때 알아 챘습니다.
나는 Shiny this January을 사용하기 시작했다. 나는 Shiny 페이지에 대한 튜토리얼을 처음으로 따라 갔고 몇 가지 블로그와 StackOverflow 질문을 숨겼다. 그래서 나는 반응성과 다른 것들로 많은 실수를하고 있다고 확신한다. 반짝 반짝 빛나는 구체적인 것들.
selectinput
관찰자 :
observeEvent(input$selectfiles, ignoreInit = T, {
if (!is.null(USER$Data)) {
if (nchar(input$selectfiles) > 1){
file <- paste0(input$selectfiles, ".RData")
# FASTQ
if (endsWith(input$selectfiles, ".fastq")){
source("LoadFastQ.R", local = T)
} else{
# CSV
source("LoadCSV.R", local = T)
}
# Force user to View tab once file is uploaded
updateTabsetPanel(session, "inTabset", selected = "DataView")
}
}
})
CSV UI
output$CSV <- renderDataTable({
datatable(
CSV_table,
filter = list(position = 'top'),
class = 'cell-border strip hover',
options = list(
search = list(regex = TRUE, caseInsensitive = TRUE),
pageLength = 10
)
)
})
output$DataOutput <- renderUI({
fluidPage(
fluidRow(
column(4,
selectInput("CSV_identifier", "Identifier",
choices = c(colnames(CSV_table)),
selected = colnames(CSV_table)[1])
),
column(
12, offset = -1,
dataTableOutput("CSV")
)
),
actionButton("clustbutton", "Clustering"),
actionButton("corrbutton", "Correlation")
)
)
})
선택 행 :
**click**
[1] "### NEW SELECT ###"
[1] 1 # index of row in CSV
[1] "A" # value of index of row in CSV
[1] 22 1642 # dim(CSV)
**click**
[1] "### NEW SELECT ###"
[1] 1 2
[1] "A" "B"
[1] 22 1642
** Selecting new file **
**click**
[1] "### NEW SELECT ###"
[1] 1
[1] "A"
[1] 22 1642
[1] "### NEW SELECT ###"
[1] 1
[1] "X"
[1] 10 5
**click**
[1] "### NEW SELECT ###"
[1] 1 2
[1] "A" "B"
[1] 22 1642
[1] "### NEW SELECT ###"
[1] 1 2
[1] "X" "Y"
[1] 10 5
: I 행을 클릭
observeEvent(input$CSV_rows_selected, ignoreInit = T, {
print("### NEW SELECT ###")
print(input$CSV_rows_selected)
CSV_selected <<- CSV_table[input$CSV_rows_selected, input$CSV_identifier]
print(CSV_selected)
print(dim(CSV_table))
})
출력
예 :
source("http://bioconductor.org/biocLite.R")
packages <-
c(
"shiny",
"DT",
"data.table",
"DESeq2",
"fpc",
"gplots",
"SCAN.UPC",
"digest",
"shinyBS",
"ggplot2",
"reshape",
"shinyjs",
"squash"
)
for (package in packages) {
if (!package %in% installed.packages()){
biocLite(package, ask = FALSE)
}
library(package, character.only = T)
}
rm(list=ls())
gc()
tableA <- data.frame(LETTERS[1:10], runif(10, 1, 100), stringsAsFactors = F)
tableB <- data.frame(LETTERS[11:20], runif(10, 1, 100), stringsAsFactors = F)
# Define UI for application that draws a histogram
ui <- navbarPage(
title = "TEST",
id = "inTabset",
# Tab 1 - Loading file
tabPanel(
title = "Load File",
value = "loadfile",
fluidRow(
useShinyjs(),
selectInput(
"selectfiles",
label = "Select loaded file",
multiple = F,
choices = c("tableA", "tableB"), selected = "tableA"
)
)
),
# Tab 2 - View Data
tabPanel(
title = "View",
value = "DataView",
useShinyjs(),
uiOutput("DataOutput")
)
)
# Define server logic required to draw a histogram
server <- function(input, output, session) {
# READ FILE AND RETURN DATA
observeEvent(input$selectfiles, {
# CSV
CSV_table <- get(input$selectfiles)
output$CSV <- renderDataTable({
datatable(
CSV_table,
filter = list(position = 'top'),
class = 'cell-border strip hover',
options = list(
search = list(regex = TRUE, caseInsensitive = TRUE),
pageLength = 10
)
)
})
output$DataOutput <- renderUI({
fluidPage(
fluidRow(
column(4,
selectInput("CSV_identifier", "Identifier",
choices = c(colnames(CSV_table)),
selected = colnames(CSV_table)[1])
),
column(
12, offset = -1,
dataTableOutput("CSV")
)
),
fluidRow(
bsModal("clusterDESeqplotwindow", "DESeq clustering", trigger = "clusterDESeq", size = 'large',
plotOutput("clusterDESeqplot"),
downloadButton("clusterDESeqplotDownload")
),
bsModal("clusterUPCplotwindow", "UPC clustering", trigger = "clusterUPC", size = 'large',
plotOutput("clusterUPCplot"),
downloadButton("clusterUPCplotDownload")
),
bsModal("clustering", "Clustering", trigger = "clustbutton", size = "large",
fluidRow(
column(5,
textOutput("bsModal_selected_rows"),
br(),
htmlOutput("bsModal_Log")
),
column(6, offset = 1,
fileInput("metadata", "Add metadata"),
selectInput("CSV_clusterparam", "Select DE parameter", choices = c(colnames(CSV_table)), selected = c(colnames(CSV_table))[2])
)
,
div(id = "clusterButtons",
column(4, align="center",
actionButton("clusterUPC", "UPC"),
actionButton("clusterDESeq", "DESeq")
)
)
)
),
actionButton("clustbutton", "Clustering"),
actionButton("corrbutton", "Correlation")
)
)
})
observeEvent(input$CSV_rows_selected, ignoreInit = T, {
print("### NEW SELECT ###")
print(input$CSV_rows_selected)
CSV_selected <<- CSV_table[input$CSV_rows_selected, input$CSV_identifier]
print(CSV_selected)
print(dim(CSV_table))
output$bsModal_selected_rows <- renderText(paste("Selected samples:", paste(CSV_selected, collapse = ", ")))
})
})
session$onSessionEnded(stopApp)
}
# Run the application
shinyApp(ui = ui, server = server)
이제 모든 작품 [태그 : datatables] 태그 나처럼 뭔가의에 대한 안 하나 [태그 : data.table] 패키지. – Frank
data.table 패키지를 사용하고 있지만 충분히 정교합니다. 이 오류는 패키지 자체에 관한 것이 아닙니다. –
자, 다 됐습니다. 어쩌면 그것은 관련되어 있습니다. 나는 반짝이는 것을 모르고 있지만, 일부 datatables를 지원한다는 것을 알고있다. – Frank