2017-04-11 89 views
0

爲簡單起見,我將只包含我遇到的代碼部分。此代碼從數據庫中提取大型數據集,並創建具有不同分析的選項卡。我遇到了使我的x變量對ggplot圖形起反應的問題。如果我在aes()中定義了x變量,那麼圖表顯示正常,但是一旦我創建一個反應輸入來替代我的變量,那麼ggplot就會遇到定義x變量的麻煩。我希望能夠切換的變量是:我的數據集中的「assay_plate_label」和「assay_read_on」。我不能讓我的x軸使用ggplot閃亮反應

ui.r

library(shiny) 


shinyUI(fluidPage(
# Header or Title Panel 
titlePanel(title = h4("HTS QC analysis", align="center")), 
sidebarLayout(
# Sidebar panel 
sidebarPanel(

    numericInput("pg_number", "Plate Group", 4552), 
    actionButton('process', 'Process Plate Group Data') 

), 


# Main Panel 
mainPanel(
    tabsetPanel(type="tab", 
tabPanel("Box Plot All", 
         selectInput('x_axis', "Choose the X axis", choices= c("Assay Plate Label"= "assay_plate_label", "Assay Date"= "assay_read_on")), 
         plotOutput("deviation")) 


    ) 

    ) 

) 
) 
) 

server.r

shinyServer(function(input, output){ 



    x_label <- reactive({ 
    switch(input$x_axis, 
     "assay_plate_label" = assay_plate_label, 
     "assay_read_on"= assay_read_on) 
}) 



    read.csv("table_na") 
[Here is a sample of the data with the variables I use in this plot ][1] 




output$deviation <- renderPlot({ 


    table_na$assay_plate_label <- as.character(table_na$assay_plate_label) 
    ggplot(table_na, aes(x_label(), y=raw_assay_value, group=as.character(x_label()))) + 
    geom_boxplot() + 
    theme(axis.text.x = element_text(angle = 90, hjust = 3, vjust= 0)) + 
    xlab("Plate Label")+ 
    ylab(table_na$plate_type_name)+ 
    geom_boxplot(outlier.colour = "red", outlier.size= 1.5)+ 
    ggtitle("All Plates Box Plot") 


}) 
}) 



} 
) 

我不得不削減大部分不必要的代碼,使其可以理解的,但是,涉及到該問題的代碼它自己都在這裏。

回答

0

不能運行代碼很難知道,但嘗試aes_string而不是aes。

+0

太棒了!這個伎倆。 –

+0

也許你可以upvote答案,因爲這是整個網站的重點。 – awchisholm

+0

事實上,我做到了,「感謝您的反饋!記錄下名聲低於15的人的投票記錄,但不會更改公開顯示的帖子得分。」 –