我正在使用热图法和绘图法绘制矩阵我想使plotylOutput的高度和宽度对矩阵的大小起反应]
如果我在plotlyOutput width参数中使用反应性值,则会出现以下错误:htmltools :: validateCssUnit中的错误:CSS单位必须是单元素数字或字符向量
请参见下面的最低版本代码:
library(shiny)
library(heatmaply)
library(plotly)
ui <- tags$div(id = "placeholderimage", uiOutput("plotlyimage"))
server <- shinyServer(function(input, output, session) {
matsample <- reactive({cbind(c("A","A","A","T"),c("A","A","A","T"),c("A","A","A","G"))})
ranges <- reactiveValues(width_im = NULL,height_im=NULL)
ranges$width_im <- reactive(ncol(matsample())*20)
ms <- reactive({
alph <- c("A"=1, "C"=2, "G"=3, "T"=4, "-"=5, "N"=6, "S"=7)
ms <- matrix(alph[matsample()], ncol = ncol(matsample()), byrow=FALSE))
rownames(ms) <- rownames(matsample())
return(ms)
})
mm <- reactive({
data.frame(do.call(rbind, lapply(rownames(ms()), rep, ncol(matsample()))))
})
output$matimage <- renderPlotly({
heatmaply(ms(), custom_hovertext = mm(),
cellnote = matsample(),cellnote_size = 6,
cellnote_textposition = "middle center",
fontsize_col = 6,grid_gap = 1,grid_size = 0.01,
show_dendrogram = c(FALSE, FALSE),
Rowv=NULL, Colv=NULL, color=rainbow(7),
hide_colorbar=FALSE, plot_method = "plotly")
})
output$plotlyimage <- renderUI(
tags$div(class="superbigimage",
plotlyOutput("testplot", **width = isolate(ranges$width_im)**)
)
})
该代码当前由于宽度= isolate(ranges $ width_im)而引发错误,如何使宽度对矩阵的大小起反应?请注意,我的实际工作中有超过600列的矩阵
output$plotlyimage <- renderUI(
tags$div(class="superbigimage",
plotlyOutput("testplot", width = ranges$width_im())
)