【发布时间】:2019-03-09 16:03:51
【问题描述】:
在我闪亮的应用程序中,我想在我的ggplot 中添加一个 geom_hline,仅当用户使用复选框选择这样做时,我还希望用户使用numericInput 设置yintercept。
我相信有一个简单的解决方案,但由于我不是编码员,所以我想问一下哪种方法最简单。
我的代码是这样的:
在用户界面中:
numericInput('hline', label ='Limits', 0)
在服务器中:
plotInput <- reactive({
ggplot(data = dataforplot(), aes(x = ID_Polymer, y = value), position = position_dodge(width = 1)) +
geom_bar(aes_string( fill=razeni()), position = position_dodge(width = 1), stat="identity", color="white")+
theme_minimal() +
theme(legend.text=element_text(size=21))+
theme(text = element_text(size=21))+
theme(panel.grid.major = element_blank(), panel.grid.minor = element_blank()) +
ggtitle(input$title_text_box_id) +
geom_hline(aes(yintercept = input$hline, linetype = "Minimal limit"), color='red', size=0.4)+
labs(x = "", y = input$ylabel_text_box_id) +
geom_text(aes(x = ID_Polymer, y = value,Group=Polymer,label=value),
position = position_dodge(width = 1),vjust=2, size=5,colour = "white", fontface = "bold") +
scale_fill_tableau("Tableau 10")+
scale_x_discrete(labels=c(xpopisky()))#puts a reactive in x labels
})
这行得通,只是我不知道如何告诉闪亮的“只有当我通过选中复选框告诉你时才显示geom_hline”,我相信应该涉及if else 循环。
非常感谢您的任何建议!
【问题讨论】:
标签: r checkbox ggplot2 shiny geom-hline