2016-02-12 72 views
0

我對閃亮我很新,我試圖建立一個Web應用程序,從GEO下載數據集或讓用戶上傳他自己的。能夠以boxplot格式和表格格式向用戶顯示數據,然後讓用戶決定是將數據進行標準化還是日誌轉換。我的問題是在代碼後面的順序actionButton不起作用。如果我按下第一個動作按鈕,然後按第二個動作按鈕,這兩個都很奇怪。但是如果我選擇直接按第二個動作按鈕,它什麼也不做。這裏是我的代碼:shiny - actionButton#1完全相同actionButton#2 doesnt

ui.R

library(shiny) 
library(som) 
shinyUI(pageWithSidebar(

    # Application title 
    # 
    headerPanel("Dataset Selection"), 
    # Sidebar with controls to select a dataset and specify the number 
    # of observations to view 
    sidebarPanel(

    actionButton("Gobutton", "Bring it up"), 

    fluidRow() 
), 

    mainPanel(
    tabsetPanel(
     tabPanel("Dataset", 
       fluidRow(
       column(8, uiOutput("dataTable"), 
         tags$style(type='text/css', '#view {background-color: rgba(11,56,49,0.2); color: black; font-family:verdana;}'))) 
    ), 
     tabPanel("Boxplot", 
       fluidRow(
       column(8,plotOutput("preprocessData"), 
         tags$style(type='text/css', '#view {background-color: rgba(11,56,49,0.2); color: black; font-family:verdana;}'))), 
       conditionalPanel(condition = "input.NormalizeButton <= 0", 
           actionButton("NormalizeButton","Normalize")), 
       conditionalPanel(condition = "input.LogTransformButton <= 0", 
           actionButton("LogTransformButton", "Log2 Transform")) 
    )) 
) 
) 
) 

server.R

shinyServer(function(input, output) { 
    library(xtable) 
    # You can access the value of the widget with input$num, e.g. 
    GSEmRNA <- data.frame(from=c(100,200,150), to=c(1000,2000,150),last= c(50,50,250)) 

    normalizeSom <- function(GSEmRNA){ 
    colnamesSAVE <- colnames(GSEmRNA) 
    GSEmRNA <- som::normalize(GSEmRNA) # Normalize the dataset using som package of R 
    colnames(GSEmRNA) <- colnamesSAVE 
    boxplot(GSEmRNA) 
    print(colnames(GSEmRNA)) 
    return(GSEmRNA) 
    } 

    todoLogTransformation <- function(GSEmRNA) { 
    GSEmRNA <- log(GSEmRNA,2) 
    boxplot(GSEmRNA) 
    return(GSEmRNA) 
    } 

    output$dataTable <- renderUI({ 
    input$Gobutton 
    if (input$Gobutton== 0) {return()}   
    else{ 
     GSEmRNAprinted <- print(xtable(head(GSEmRNA), align=rep("c", ncol(GSEmRNA)+1)), 
           floating=FALSE, tabular.environment="array", comment=FALSE, print.results=FALSE) 
     html <- paste0("$$", GSEmRNAprinted, "$$") 
     list(
     withMathJax(HTML(html)))} 
    }) 
    output$preprocessData <- renderPlot({ 
    if (input$Gobutton== 0) {return()}   
    else{ 
    boxplot(GSEmRNA) 
    input$LogTransformButton 
    if(input$LogTransformButton ==0){return()} 
    else if(input$LogTransformButton != 0){ 
     GSEmRNA <<- todoLogTransformation(GSEmRNA) 
    } 
    input$NormalizeButton 
    if(input$NormalizeButton ==0){return()} 
    else if(input$NormalizeButton != 0){ 
     GSEmRNA <<- normalizeSom(GSEmRNA) 
    }} 
    }) 

}) 

還有最後一點,我想我在輸出$ dataTable的<描述表 - renderUI換新各時間用戶按下標準化或記錄變換。任何幫助是極大的讚賞。我一直在這一段時間

+0

這將是更容易幫助你,如果你能提供你的程序的一個非常簡化的版本。嘗試使用最小的庫來分離問題,也許只是在這種情況下閃亮。 – Geovany

+0

我將代碼修改爲更簡約。感謝您的輸入 –

+0

嘗試使用簡單的'data.frame'來創建示例以顯示您想要的內容(允許沒有'GEOquery'的人試圖修復它)。此外,您可能必須使用'reactiveValues'來處理數據(而不是使用'<< - ')。參見'observeEvent',它允許你改變你的'reactiveValues'編輯完成。 – Batanichek

回答

1

試試這個:

1)從你的代碼全部刪除不影響什麼(CSS和panel--爲簡單起見)

2)所有功能之外聲明服務器 - 認爲它會更好地工作

3)使用無功值數據

UI

library(shiny) 
library(som) 
shinyUI(pageWithSidebar(

    headerPanel("Dataset Selection"), 

    sidebarPanel(
    actionButton("Gobutton", "Bring it up") 
), 
    mainPanel(
    wellPanel(
       fluidRow(
       column(8, uiOutput("dataTable") 
         )) 
    ), 
    wellPanel(
       fluidRow(
       column(8,plotOutput("preprocessData") 
         )), 
       conditionalPanel(condition = "input.NormalizeButton <= 0", 
           actionButton("NormalizeButton","Normalize")), 
       conditionalPanel(condition = "input.LogTransformButton <= 0", 
           actionButton("LogTransformButton", "Log2 Transform")) 

) 
) 
) 
) 

服務器

normalizeSom <- function(GSEmRNA){ 
    colnamesSAVE <- colnames(GSEmRNA) 
    GSEmRNA <- som::normalize(GSEmRNA) # Normalize the dataset using som package of R 
    colnames(GSEmRNA) <- colnamesSAVE 
    return(GSEmRNA) 
} 

todoLogTransformation <- function(GSEmRNA) { 
    GSEmRNA <- log(GSEmRNA,2) 
    return(GSEmRNA) 
} 

shinyServer(function(input, output) { 
    library(xtable) 
    # You can access the value of the widget with input$num, e.g. 
    GSEmRNA <- data.frame(from=c(100,200,150), to=c(1000,2000,150),last= c(50,50,250)) 
    data_for_use=reactiveValues(d=GSEmRNA) 


    output$dataTable <- renderUI({ 
    if (input$Gobutton== 0) {return()}   
    else{ 
     GSEmRNAprinted <- print(xtable(head(data_for_use$d), align=rep("c", ncol(data_for_use$d)+1)), 
           floating=FALSE, tabular.environment="array", comment=FALSE, print.results=FALSE) 
     html <- paste0("$$", GSEmRNAprinted, "$$") 
     list(
     withMathJax(HTML(html)))} 
    }) 

    output$preprocessData <- renderPlot({ 

    if (input$Gobutton== 0) {return() 
    }else{ 
     boxplot(data_for_use$d) 

     } 
    }) 

    observeEvent(input$NormalizeButton,{ 
    data_for_use$d=normalizeSom(data_for_use$d) 
    }) 
    observeEvent(input$LogTransformButton,{ 
    data_for_use$d=todoLogTransformation(data_for_use$d) 
    }) 
}) 
+0

不得不把所有的功能放回到裏面,因爲不能使它以這種方式工作,但最終這個答案使我達到了一個正常工作的閃亮的Web應用程序。非常感謝,非常感謝 –