R shiny error: Error in html tools::validateCssUnit(height); CSS units must be a single-element numeric or character vector

偶尔善良 提交于 2021-01-28 09:13:49

问题


Am learning to use R shiny and I am trying to create a heatmap that allows the user to specify the height in plotlyOutput to prevent labels from being clumped together. My minimal working code:

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)

回答1:


The constraint is related to the heatmaply package, the solution below is temporary while plotly continues to accept the height argument in layout.

Warning: Specifying width/height in layout() is now deprecated. Please specify in ggplotly() or plot_ly()

You could approach the developer on their GitHub and raise and issue or better yet a pull request with the changes you propose. For the time being, the solution below works with Plotly 4.7.1.

app.R

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)


来源:https://stackoverflow.com/questions/48737864/r-shiny-error-error-in-html-toolsvalidatecssunitheight-css-units-must-be-a

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!