2016-02-12 73 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应用程序。非常感谢,非常感谢 –