闪亮 - actionButton#1完全相同的actionButton#2不

时间:2016-02-12 16:09:51

标签: r shiny

我很擅长闪亮,我正在尝试构建一个从GEO下载数据集或让用户上传自己的数据集的Web应用程序。能够以boxplot格式和表格格式向用户显示数据,然后让用户决定数据是规范化还是日志转换。我的问题是在后面的代码中的actionButton代码不起作用。如果我按下第一个动作按钮,然后按第二个动作按钮,两者都很奇怪。但如果我选择直接按第二个动作按钮它什么都不做。这是我的代码:

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&lt; - renderUI中描述的表都要更新。任何帮助是极大的赞赏。我一直在研究这个问题

1 个答案:

答案 0 :(得分:1)

试试这个:

1)从代码中删除所有不影响的内容(css和panel--为简单起见)

2)所有功能都在服务器外部声明 - 认为它会更好用

3)使用数据的反应值

UI

tuple

服务器

df = sc.parallelize([
    (list(k), ) + 
    v[0] + 
    v[1:] 
    for k, v in  dic.items()
]).toDF(['key', 'val_1', 'val_2', 'val_3', 'val_4', 'val_5', 'val_6'])

df.show()

## +--------------------+-----+-----+-----+-----+-----+-----+
## |                 key|val_1|val_2|val_3|val_4|val_5|val_6|
## +--------------------+-----+-----+-----+-----+-----+-----+
## |     [aaa, bbb, ccc]|  0.3|  1.2|  1.3|  1.5|  1.4|    1|
## |[kkk, ggg, ccc, sss]|  0.6|  1.2|  1.7|  1.5|  1.4|    2|
## +--------------------+-----+-----+-----+-----+-----+-----+