我尝试了我的第一个Markdown博士,一切顺利,直到 我收到了错误
"Error in eval(expr, envir, enclos) : object 'input' not found"
有这个块
{r, echo=FALSE}
inputPanel(
radioButtons("category",label= "Select Category",choices=c("diffPts","diffGF","diffGA","diffGD","diffpos"),inline = TRUE)
)
renderPlot({
ggplot(clubSeason, aes(x=team, y=input$category)) + geom_boxplot()
})
如果我硬编码,例如显示图表y="diffPts"
。在ggplot周围放置一个print()
无济于事
TIA
答案 0 :(得分:2)
以下运行正常。 “输入$ category”的值按预期打印
---
title: "Untitled"
runtime: shiny
output: html_document
---
```{r, echo=FALSE}
library(ggplot2)
inputPanel(
radioButtons("category",label= "Select Category",choices=c("diffPts","diffGF","diffGA","diffGD","diffpos"),inline = TRUE)
)
renderPlot({
print(input$category)
ggplot(faithful, aes(x=eruptions, y=waiting)) + geom_boxplot()
})
```
更新:
问题似乎是aes
函数传递了一个字符串。您可以改为使用aes_string
:
renderPlot({
ggplot(clubSeason, aes_string(x='team', y=input$category)) + geom_boxplot()
})