gpt4 book ai didi

r - 如何在 Shiny 的上下文中更改绘图的高度

转载 作者:行者123 更新时间:2023-12-03 21:15:31 25 4
gpt4 key购买 nike

如下图所示,当在侧栏中选择多个县时,我的图的高度保持不变。这使得情节过于拥挤,以至于标签变得不可读。我想根据侧栏中选择的县数来改变我的情节的高度。我怎样才能做到这一点?

下面,请查看我认为需要修改的部分代码。

enter image description here

界面元素

mainPanel(plotOutput("workforce_plot"), 

服务器元素
workforce_plot <- reactive({
ggplot(workforce_data(), aes(x =Age_Group, y = Percentage, fill=County.y)) +
geom_bar(stat = "identity",position = position_dodge()) +
geom_text(
aes(label = Percentage2),
vjust = 0.5,
colour = "black",
position = position_dodge(width=0.9),
fontface = "bold",
size=3.2,
hjust = 0)+
ylim(0,110)+
coord_flip()+

labs(
x = "Age Groups",
y = "Percentage",
face = "bold")
})

output$workforce_plot <- renderPlot ({
workforce_plot()
})

最佳答案

您可以添加 height您的 renderPlot 的参数函数,并将一个函数传递给它,该函数根据一些相关的 react 调整高度。

一个例子:

output$workforce_plot <- renderPlot ({ 
workforce_plot()
}, height = function() {200 + (length(workforce_data()[["County.y]]) *.2)})

(它也可能类似于 length(input$country) 而不是响应式(Reactive)表达式。)

然后在 ui.R定义 height = 'auto'对于那个面板。

关于r - 如何在 Shiny 的上下文中更改绘图的高度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61080912/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com