【发布时间】:2022-01-16 15:22:16
【问题描述】:
我正在尝试制作一个使用此功能的 Shiny 应用程序(用 R markdown 制作):
ls_vs <- function(variable) {
dataset %>%
filter({{variable}} != 254.948530) %>%
filter({{variable}} != 121.738080) %>%
ggplot(mapping = aes(y = life_satisfaction, x = {{variable}})) +
geom_point(aes(color = region, shape = freedom_status), size = 2) +
geom_smooth(color = "cyan") +
labs(y = "Life Satisfaction", shape = "Freedom Status", color = "Continent")
}
ls_vs(economic_freedom)
我用这个函数得到了想要的结果:
现在这是我将其集成到闪亮应用中的尝试:
用户界面部分:
tabPanel("Factor Comparision",
sidebarPanel(
varSelectInput(inputId = "variable", label = "Select Factor to Compare", data = dataset),
mainPanel(
h1("Test"),
plotOutput("ls_vs"),
)
)),
这里是服务器部分:
#Factor Comparisons
output$ls_vs <- renderPlot({
dataset%>%
filter({{input$variable}} != 254.948530) %>%
filter({{input$variable}} != 121.738080) %>%
ggplot(mapping = aes(y = life_satisfaction, x = {{input$variable}})) +
geom_point(aes(color = region, shape = freedom_status), size = 2) +
geom_smooth(color = "cyan") +
labs(y = "Life Satisfaction", shape = "Freedom Status", color = "Continent")
})
在尝试运行应用程序时,我收到了错误:
错误:arg 必须是符号
我是否在 UI 区域或服务器区域做错了什么?如何在 Shiny 中正确使用 varSelectInput 来制作交互式 ggplot,可以在其中更改变量以更改绘图?
非常感谢!
【问题讨论】:
标签: r ggplot2 shiny shiny-server