Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.2k views
in Technique[技术] by (71.8m points)

r - Rmarkdown and Shiny input

I'm attempting my first Markdown doc and everything has been going smoothly until I get the error

 "Error in eval(expr, envir, enclos) : object 'input' not found"

with this chunk

{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()
})

if I hardcode e.g y="diffPts" the chart displays. Putting a print() around the ggplot does not help

TIA

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Following runs fine for me. The value of ìnput$category` is printied as expected

---
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()
})
```

UPDATE:

The issue appears to be with the aes function being passed a string. You can use aes_string instead:

renderPlot({
   ggplot(clubSeason, aes_string(x='team', y=input$category)) + geom_boxplot()
})

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...