shiny - 滚动条如何包含在图例中?
问题描述
很高兴看到超过 18 行的图例。
将输出包装在 wellPanel( style = 'overflow-y:scroll;' ) 中似乎是正确的功能,但没有奏效。
library(shiny)
shinyApp(
ui <- fluidPage(
splitLayout(cellWidths = c('20%', '30%', '50%'),
sliderInput('mySldr' , value = 4 , min = 1 ,
label = 'how many groups ?', max = 44 ), # max 52 > 44
plotOutput( 'myLgnd' ),
plotOutput( 'myPlt' )
)
),
server <- function(input, output, session) {
n <- reactive({ input$mySldr })
theD <- reactive({ matrix(runif( 5*n() ), nrow = 5,
dimnames = (list( 1:5, rep(letters,2)[ 1:n() ] ))) })
output$myLgnd <- renderPlot({
legend( x = 'center', legend = colnames( theD() ),
fill = rainbow( n() ) ) })
output$myPlt <- renderPlot({
matplot( x = c(2001:2005), type = 'o', xlab = '', ylab = '',
y = theD() , col = rainbow( n() ) ) })
}
)
任何对可滚动图例的帮助将不胜感激。谢谢你。
解决方案
不是很健壮,但这适用于您的示例:
div(
style = "overflow-y: auto; overflow-x: hidden",
plotOutput( 'myLgnd' )
),
和
output$myLgnd <- renderPlot({
par(mar = c(0,0,0,0))
legend( x = 'center', legend = colnames( theD() ),
fill = rainbow( n() ) ) }, height = function(){170+10*ncol(theD())})
我已经找到了这些值170
,并且10
经过多次试验错误。也许有更好的价值。
最好用plotly
.
推荐阅读
- ansible - 在ansible中使用with_sequence在with_subelement上循环
- selenium - Selenium Webdrive 所需的自动化建议
- python - Python Pandas new dataframe column with group by and condition
- flutter - Flutter TextField - how to shrink the font if the text entered overflows
- css - Changing the Visual Composer CSS path to prevent https errors
- jquery - JQuery JSON 键集自动完成
- r - 我怎样才能最干净地使用 Roxygen2 来记录 R 中的向量
- html - How to support HTML dom elements with RTL / LTR languages?
- php - "SQLSTATE[HY000]: General error: 1364 Field 'user_id' doesn't have a default value (SQL: insert into
- dpdk - dpdk vmxnet3 clear stats missing (?) implementation