【问题标题】:Port heatmap.2 plot to shiny (object not found issue)端口 heatmap.2 绘制到闪亮(找不到对象问题)
【发布时间】:2016-10-04 16:23:21
【问题描述】:

我在尝试将手动 R 脚本移植到闪亮时遇到了一些问题。原始脚本读取数据表并使用 gplots 包绘制热图(heatmap.2)。它完美地工作。这是输入文件:

绘制热图的原始代码是:

library(RColorBrewer)
library(gplots)

#setwd("C:\\Users\\rafael.batista\\Documents\\shiny_locally\\dist\\shiny\\workplace")
my_data_24.12 <- read.table("24-12_windPRO_chicoloma.txt", header = FALSE, sep = "\t", dec = ".", stringsAsFactors=FALSE) # reading 24-12 table copied from windPRO
my_data_24.12 <- my_data_24.12[-c(1,26),]
my_data_24.12 <- my_data_24.12[,-c(1, 14)]
my_data_24.12 <- data.matrix(my_data_24.12)

min.v <- min(my_data_24.12)
max.v <- max(my_data_24.12)

# Agora o heatmap:
rnames <- c("00:00", "01:00", "02:00", "03:00", "04:00", "05:00", "06:00", "07:00", "08:00", "09:00", "10:00", "11:00", "12:00", "13:00", "14:00", "15:00", "16:00", "17:00", "18:00", "19:00", "20:00", "21:00", "22:00", "23:00")
rownames(my_data_24.12) <- rnames
cnames <- c("Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec")
colnames(my_data_24.12) <- cnames

my_palette <- colorRampPalette(c("chartreuse4", "yellow", "red", "darkmagenta"))(n = 199)

col_breaks = c(seq(min.v,9.999,length=100),  # for 1st interval
               seq(10,11.999,length=50),              # for 2nd interval
               seq(12,max.v,length=50))              # for 3rd interval


heatmap.2(my_data_24.12, na.rm = TRUE, Rowv = FALSE, Colv = FALSE, key = FALSE, density.info = "none", trace = "none",
          cellnote = round(my_data_24.12, digits = 1), notecol = "black", xlab = "Months", ylab = "Hours",
          colsep=c(1,2,3,4,5,6,7,8,9,10,11,12), srtCol=0,
          rowsep = c(0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23),
          col = my_palette,
          margins =c(3.5,5),
          lhei = c(0.05,1),
          lwid = c(0.02, 0.7),
          adjCol = c(0.5,1),
          breaks=col_breaks,
          sepcolor = "white")

现在的问题。我正在尝试使用以下代码将其移植到闪亮:(这是 server.r)

data_24.12 <- reactive({      #(file will be loaded by fileInput in ui.r)
  if(input$Load3 == 0){return()}
  inFile3 <- input$file3
  if (is.null(inFile3)){return(NULL)}


  isolate({ 
    input$Load3
    my_data_24.12 <- read.table(inFile3$datapath, header = FALSE, sep = "\t", dec = ".", stringsAsFactors=FALSE) # reading table
    my_data_24.12[-c(1,26),] #doing some processing...
    my_data_24.12 <- my_data_24.12[,-c(1, 14)]
    my_data_24.12 <- data.matrix(my_data_24.12)

    rownames(my_data_24.12) <- c("00:00", "01:00", "02:00", "03:00", "04:00", "05:00", "06:00", "07:00", "08:00", "09:00", "10:00", "11:00", "12:00", "13:00", "14:00", "15:00", "16:00", "17:00", "18:00", "19:00", "20:00", "21:00", "22:00", "23:00")
    colnames(my_data_24.12) <- c("Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec")

    my_palette <- colorRampPalette(c("chartreuse4", "yellow", "red", "darkmagenta"))(n = 199)
    min.v <- min(my_data_24.12)
    max.v <- max(my_data_24.12)

    col_breaks = c(seq(min.v,9.999,length=100),   # for 1st interval
                   seq(10,11.999,length=50),      # for 2nd interval
                   seq(12,max.v,length=50))       # for 3rd interval

    })


  my_data_24.12 
})
#==============================


# Outputs:

output$plot_hourly_windpro <- renderPlot({
   heatmap.2(data_24.12(), na.rm = TRUE, Rowv = FALSE, Colv = FALSE, key = FALSE, density.info = "none", trace = "none",
            cellnote = round(my_data_24.12, digits = 1), notecol = "black", xlab = "Months", ylab = "Hours",
            colsep=c(1,2,3,4,5,6,7,8,9,10,11,12), srtCol=0,
            rowsep = c(0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23),
            col = my_palette,
            margins =c(3.5,5),
            lhei = c(0.02,0.95),
            lwid = c(0.02,0.95),
            adjCol = c(0.5,0.2),
            breaks=col_breaks,
            sepcolor = "white")})

我收到以下错误:

收听http://127.0.0.1:6897
警告:重复错误:找不到对象“col_breaks”
堆栈跟踪(最内层优先):
78:重复
77:热图.2
76:渲染图[/home/rafael/Documentos/wobben/shiny_version/shiny/server.R#81] 68: 输出$plot_hourly_windpro 1:运行应用程序

看起来闪亮的没有找到一些对象。我现在认为它必须与数据处理有关......但我不知道出了什么问题。

有人可以帮忙吗? (我没有在此处粘贴 ui.r,因为我很确定问题出在 server.r 中)

非常感谢!

【问题讨论】:

  • 只是一个小旁注...这不是整个 server.r 代码...只是它的一部分。缺少初始部分(库加载... shinySever()...等)。

标签: r shiny heatmap


【解决方案1】:

我也遇到过类似的问题,但是有一个 plolty 元素,你应该尽量避免在绘图代码中使用反应性数据集,也许试试这个:

... output$plot_hourly_windpro <- renderPlot({

data.plot<-data_24.12()
   heatmap.2(data.plot, na.rm = TRUE, ...

希望对你有帮助;)

【讨论】:

    猜你喜欢
    • 2019-01-21
    • 1970-01-01
    • 1970-01-01
    • 2019-12-21
    • 2015-04-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多