2015-06-15 52 views
0

我正在同时过滤tbale和热图。 在过滤过程中,表格的宽度发生变化,使得特定列的宽度保持不变。R Shiny - 设置绘图输出的无功宽度

过滤期间热图的宽度保持不变。我想让热图像桌子一样改变其重量。我有一个功能,试了一下:

width = function() {70*ncol(labelSub()) 

但doesn`将不起作用......

谢谢你的任何建议

shinyUI(fluidPage(
     titlePanel("title panel"), 

     sidebarLayout(

    sidebarPanel(
     selectInput("select_name", 
        label = "name", 
        choices = c("all", "A", "B", "C", "D","E"), 
        selected = "all"), 

    selectInput("select_type", 
       label = "Type", 
      choices = c("all", "M", "FFF"), 
      selected = "all") 
    ), 

    mainPanel(
    tableOutput("lab"), 
    plotOutput("main_plot", width="auto") 
) 
) 
)) 


library(quantmod) 

f <- function() sample(seq(1:10), 25, replace=TRUE) 

in1 <- cbind (f(), f(), f(), f(), f(), f()) 
label <- data.frame(L1= c(rep("A", 5), rep("B", 5), rep("C", 5), rep("D", 5), rep("E", 5)), L2=(sample(c("M", "FFF"), 25, replace=TRUE)), ID=seq(1,25)) 

label_sub <- label 


shinyServer(function(input, output) { 

    labelSub <- reactive({ 
    label_sub <- label 

    if (input$select_type!="all") 
    { 
     label_sub <- subset(label_sub, label_sub$L2==input$select_type) 
    } 


    if (input$select_name!="all") 
    { 
     label_sub <- subset(label_sub, label_sub$L1==input$select_name) 
    } 

    return(label_sub) 
    }) 

    output$main_plot <- renderPlot({ 
    plot.new() 
    # Access subsetted data via labelSub() 
    IDs <- labelSub()[,3] 
    par(mar=c(0, 0, 0, 0)); barplot(1:10, xaxs="i", ylim=c(0,10), space=0) 

    for_plot <- in1[IDs,] 
    if(is.matrix(for_plot)==FALSE) 
    {for_plot <- t(as.matrix(for_plot))} 

    image(for_plot) 
    }, width = function() {70*ncol(labelSub())}) 

    output$lab <- renderTable({ 
    t(labelSub())}, include.rownames=FALSE) 

}) 

回答