R闪亮错误:html工具中的错误::ValidateCSUnit(高度);CSS单位必须是单元素数字或字符向量

R闪亮错误:html工具中的错误::ValidateCSUnit(高度);CSS单位必须是单元素数字或字符向量,r,shiny,R,Shiny,我正在学习使用R Shining,我正在尝试创建一个热图,允许用户在plotlyOutput中指定高度,以防止标签聚集在一起。我的最小工作代码: library(shiny) library(plotly) ui <- fluidPage( titlePanel("Heatmap"), sidebarLayout( sidebarPanel( sliderInput("mapHeight", "Heatmap Height",

我正在学习使用R Shining,我正在尝试创建一个热图,允许用户在plotlyOutput中指定高度,以防止标签聚集在一起。我的最小工作代码:

library(shiny)
library(plotly)

ui <- fluidPage(

titlePanel("Heatmap"),
sidebarLayout(
sidebarPanel(
  sliderInput("mapHeight", 
              "Heatmap Height", 
               min = 500, 
               max = 1000,
               value =500),
  sliderInput("L", "left adjust", min = 0, max =900, value = 80)
  ),
  mainPanel(plotlyOutput("heatmap"))
  )
  )

server <- function(input, output) {

 output$heatmap <- renderPlotly({ 
 p<- heatmaply(mtcars, plot_method = "plotly")%>% 
  layout(margin = list(l = input$L, r =50 , t=0, b=90))
 #not sure why this is being ignored
 ggplotly(p, height = input$mapHeight)
 })
 }

shinyApp(ui = ui, server = server)
库(闪亮)
图书馆(绘本)

ui该约束与
heatmaply
包相关,下面的解决方案是临时的,而
plotly
继续接受
布局中的
height
参数

警告:现在不推荐在布局()中指定宽度/高度。 请在ggplotly()或plot_ly()中指定

您可以与开发人员联系,提出并发布一个请求,或者更好地说是一个包含您建议的更改的请求。目前,以下解决方案适用于Plotly 4.7.1

应用程序R
库(闪亮)
图书馆(热图)

ui如果将初始值设置为
滑块put
,会发生什么情况?如果它以无效值开头,您将收到错误。如果你问题中的代码代表a,那会很有帮助。我实际上已经将sliderInput设置为:sliderInput(“mapHeight”,“Heatmap Height”,min=500,max=1000,value=500)。所以起始值是500。我很抱歉没有发布可复制的代码,我只是觉得太长了。你的代码正是我需要的。但是,我使用的热图不是ggplot对象,因此当我尝试使用ggploty时,它会忽略输入(我不会对用户更改高度做出反应)。我正在使用heatmaply构建热图。你知道调整高度的其他方法吗?我做了很多尝试,但都没有成功。我编辑了我的原始帖子,并提供了最少的工作代码。提前感谢您的帮助。@EddyZavala,修改了我的解决方案
library(shiny)
library(heatmaply)

ui <- fluidPage(

  titlePanel("Heatmap"),
  sidebarLayout(
    sidebarPanel(
      sliderInput("mapHeight", "Heatmap Height",
                  min = 500, max = 1000, value = 500),
      sliderInput("L", "left adjust", min = 0, max = 900, value = 80)
    ),
    mainPanel(plotlyOutput("heatmap"))
  )
)

server <- function(input, output) {

  output$heatmap <- renderPlotly({

    heatmaply(mtcars) %>%
      layout(margin = list(l = input$L, r = 50, t = 0, b = 90),
             height = input$mapHeight)

  })
}

shinyApp(ui = ui, server = server)