【发布时间】:2018-02-12 00:13:33
【问题描述】:
我正在学习使用 R shiny,我正在尝试创建一个热图,允许用户在 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)
【问题讨论】:
-
如果您为
sliderInput设置初始值会发生什么?如果它以无效值开头,您将收到错误消息。如果您问题中的代码代表minimal reproducible example,那将很有帮助。 -
我实际上将 sliderInput 设置为:sliderInput("mapHeight", "Heatmap Height", min= 500, max =1000, value = 500)。所以起始值是 500。我很抱歉没有发布可重现的代码,我只是觉得它太长了。