Render GGPLOT in Shiny Notebook [duplicate]
This question already has an answer here:
Shiny: passing input$var to aes() in ggplot2
1 answer
I am new to Shiny Notebooks in R. I'm just tinkering around trying to learn. I am trying to get a ggplot to look right in the HTML document output, but I cannot get the scaling correct. If I run the same ggplot in the Shiny notebook without using input variables it looks the way I would expect. Why does this happen?
The follow code produces an output that is unusable:
```{r selectInput for iris database}
selectInput("x_axis", "X-Axis",
choices = names(iris))
selectInput(inputId = "y_axis", label = "Y-Axis",
choices = names(iris))
renderPlot({
ggplot(iris, aes(input$x_axis, input$y_axis, colour = Species)) +
geom_point()
})
The following code works correctly:
##GGPLOT Example
```{r}
ggplot(iris, aes(Petal.Length, Sepal.Length, colour = Species)) +
xlim(0,10) +
ylim(0,10) +
geom_point()
```
r ggplot2 shiny
marked as duplicate by PoGibas, Axeman
StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;
$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');
$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Jan 1 at 18:57
This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
add a comment |
This question already has an answer here:
Shiny: passing input$var to aes() in ggplot2
1 answer
I am new to Shiny Notebooks in R. I'm just tinkering around trying to learn. I am trying to get a ggplot to look right in the HTML document output, but I cannot get the scaling correct. If I run the same ggplot in the Shiny notebook without using input variables it looks the way I would expect. Why does this happen?
The follow code produces an output that is unusable:
```{r selectInput for iris database}
selectInput("x_axis", "X-Axis",
choices = names(iris))
selectInput(inputId = "y_axis", label = "Y-Axis",
choices = names(iris))
renderPlot({
ggplot(iris, aes(input$x_axis, input$y_axis, colour = Species)) +
geom_point()
})
The following code works correctly:
##GGPLOT Example
```{r}
ggplot(iris, aes(Petal.Length, Sepal.Length, colour = Species)) +
xlim(0,10) +
ylim(0,10) +
geom_point()
```
r ggplot2 shiny
marked as duplicate by PoGibas, Axeman
StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;
$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');
$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Jan 1 at 18:57
This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
add a comment |
This question already has an answer here:
Shiny: passing input$var to aes() in ggplot2
1 answer
I am new to Shiny Notebooks in R. I'm just tinkering around trying to learn. I am trying to get a ggplot to look right in the HTML document output, but I cannot get the scaling correct. If I run the same ggplot in the Shiny notebook without using input variables it looks the way I would expect. Why does this happen?
The follow code produces an output that is unusable:
```{r selectInput for iris database}
selectInput("x_axis", "X-Axis",
choices = names(iris))
selectInput(inputId = "y_axis", label = "Y-Axis",
choices = names(iris))
renderPlot({
ggplot(iris, aes(input$x_axis, input$y_axis, colour = Species)) +
geom_point()
})
The following code works correctly:
##GGPLOT Example
```{r}
ggplot(iris, aes(Petal.Length, Sepal.Length, colour = Species)) +
xlim(0,10) +
ylim(0,10) +
geom_point()
```
r ggplot2 shiny
This question already has an answer here:
Shiny: passing input$var to aes() in ggplot2
1 answer
I am new to Shiny Notebooks in R. I'm just tinkering around trying to learn. I am trying to get a ggplot to look right in the HTML document output, but I cannot get the scaling correct. If I run the same ggplot in the Shiny notebook without using input variables it looks the way I would expect. Why does this happen?
The follow code produces an output that is unusable:
```{r selectInput for iris database}
selectInput("x_axis", "X-Axis",
choices = names(iris))
selectInput(inputId = "y_axis", label = "Y-Axis",
choices = names(iris))
renderPlot({
ggplot(iris, aes(input$x_axis, input$y_axis, colour = Species)) +
geom_point()
})
The following code works correctly:
##GGPLOT Example
```{r}
ggplot(iris, aes(Petal.Length, Sepal.Length, colour = Species)) +
xlim(0,10) +
ylim(0,10) +
geom_point()
```
This question already has an answer here:
Shiny: passing input$var to aes() in ggplot2
1 answer
r ggplot2 shiny
r ggplot2 shiny
edited Jan 1 at 14:28
PoGibas
17.1k144378
17.1k144378
asked Jan 1 at 13:37
TravisTravis
11
11
marked as duplicate by PoGibas, Axeman
StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;
$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');
$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Jan 1 at 18:57
This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
marked as duplicate by PoGibas, Axeman
StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;
$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');
$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Jan 1 at 18:57
This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
add a comment |
add a comment |
2 Answers
2
active
oldest
votes
You shouldn't be providing options to aes
using [
, [[
or $
as ggplot
expects bare variable names within aes
. For this instance aes_string
is provided where you can provides the aes
a string values, which works well with selectInput
from shiny
.
The chunk below should work when rendered in a notebook with runtime: shiny
```{r selectInput for iris database, echo = FALSE, message = FALSE}
library(tidyverse)
library(shiny)
selectInput("x_axis", "X-Axis",
choices = names(iris))
selectInput(inputId = "y_axis", label = "Y-Axis",
choices = names(iris))
renderPlot({
ggplot(iris, aes_string(input$x_axis, input$y_axis, colour = "Species")) +
geom_point()
})
```
add a comment |
You need to call the data into your aes() block, not just the header name. When you call 'input$x_axis' it reads it as Sepal.Length, but does not pull the data in. I've included an example below:
renderPlot({
library(tidyverse)
data = iris %>%
select(Species, input$x_axis, input$y_axis)
ggplot(data, aes(x = data[,2], y = data[,3], colour = Species)) +
geom_point()
})
Side note: I'd suggest you also clean up the dropdown lists so one cannot select two of the same and also cannot select Species..
1
Unfortunately, this is not a good general strategy as facetting may create big problems and data may end up in the wrong facet. Use the appropriate non-standard evaluation, or useaes_
oraes_string
.
– Axeman
Jan 1 at 18:57
add a comment |
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
You shouldn't be providing options to aes
using [
, [[
or $
as ggplot
expects bare variable names within aes
. For this instance aes_string
is provided where you can provides the aes
a string values, which works well with selectInput
from shiny
.
The chunk below should work when rendered in a notebook with runtime: shiny
```{r selectInput for iris database, echo = FALSE, message = FALSE}
library(tidyverse)
library(shiny)
selectInput("x_axis", "X-Axis",
choices = names(iris))
selectInput(inputId = "y_axis", label = "Y-Axis",
choices = names(iris))
renderPlot({
ggplot(iris, aes_string(input$x_axis, input$y_axis, colour = "Species")) +
geom_point()
})
```
add a comment |
You shouldn't be providing options to aes
using [
, [[
or $
as ggplot
expects bare variable names within aes
. For this instance aes_string
is provided where you can provides the aes
a string values, which works well with selectInput
from shiny
.
The chunk below should work when rendered in a notebook with runtime: shiny
```{r selectInput for iris database, echo = FALSE, message = FALSE}
library(tidyverse)
library(shiny)
selectInput("x_axis", "X-Axis",
choices = names(iris))
selectInput(inputId = "y_axis", label = "Y-Axis",
choices = names(iris))
renderPlot({
ggplot(iris, aes_string(input$x_axis, input$y_axis, colour = "Species")) +
geom_point()
})
```
add a comment |
You shouldn't be providing options to aes
using [
, [[
or $
as ggplot
expects bare variable names within aes
. For this instance aes_string
is provided where you can provides the aes
a string values, which works well with selectInput
from shiny
.
The chunk below should work when rendered in a notebook with runtime: shiny
```{r selectInput for iris database, echo = FALSE, message = FALSE}
library(tidyverse)
library(shiny)
selectInput("x_axis", "X-Axis",
choices = names(iris))
selectInput(inputId = "y_axis", label = "Y-Axis",
choices = names(iris))
renderPlot({
ggplot(iris, aes_string(input$x_axis, input$y_axis, colour = "Species")) +
geom_point()
})
```
You shouldn't be providing options to aes
using [
, [[
or $
as ggplot
expects bare variable names within aes
. For this instance aes_string
is provided where you can provides the aes
a string values, which works well with selectInput
from shiny
.
The chunk below should work when rendered in a notebook with runtime: shiny
```{r selectInput for iris database, echo = FALSE, message = FALSE}
library(tidyverse)
library(shiny)
selectInput("x_axis", "X-Axis",
choices = names(iris))
selectInput(inputId = "y_axis", label = "Y-Axis",
choices = names(iris))
renderPlot({
ggplot(iris, aes_string(input$x_axis, input$y_axis, colour = "Species")) +
geom_point()
})
```
answered Jan 1 at 18:49
Jake KauppJake Kaupp
5,65721428
5,65721428
add a comment |
add a comment |
You need to call the data into your aes() block, not just the header name. When you call 'input$x_axis' it reads it as Sepal.Length, but does not pull the data in. I've included an example below:
renderPlot({
library(tidyverse)
data = iris %>%
select(Species, input$x_axis, input$y_axis)
ggplot(data, aes(x = data[,2], y = data[,3], colour = Species)) +
geom_point()
})
Side note: I'd suggest you also clean up the dropdown lists so one cannot select two of the same and also cannot select Species..
1
Unfortunately, this is not a good general strategy as facetting may create big problems and data may end up in the wrong facet. Use the appropriate non-standard evaluation, or useaes_
oraes_string
.
– Axeman
Jan 1 at 18:57
add a comment |
You need to call the data into your aes() block, not just the header name. When you call 'input$x_axis' it reads it as Sepal.Length, but does not pull the data in. I've included an example below:
renderPlot({
library(tidyverse)
data = iris %>%
select(Species, input$x_axis, input$y_axis)
ggplot(data, aes(x = data[,2], y = data[,3], colour = Species)) +
geom_point()
})
Side note: I'd suggest you also clean up the dropdown lists so one cannot select two of the same and also cannot select Species..
1
Unfortunately, this is not a good general strategy as facetting may create big problems and data may end up in the wrong facet. Use the appropriate non-standard evaluation, or useaes_
oraes_string
.
– Axeman
Jan 1 at 18:57
add a comment |
You need to call the data into your aes() block, not just the header name. When you call 'input$x_axis' it reads it as Sepal.Length, but does not pull the data in. I've included an example below:
renderPlot({
library(tidyverse)
data = iris %>%
select(Species, input$x_axis, input$y_axis)
ggplot(data, aes(x = data[,2], y = data[,3], colour = Species)) +
geom_point()
})
Side note: I'd suggest you also clean up the dropdown lists so one cannot select two of the same and also cannot select Species..
You need to call the data into your aes() block, not just the header name. When you call 'input$x_axis' it reads it as Sepal.Length, but does not pull the data in. I've included an example below:
renderPlot({
library(tidyverse)
data = iris %>%
select(Species, input$x_axis, input$y_axis)
ggplot(data, aes(x = data[,2], y = data[,3], colour = Species)) +
geom_point()
})
Side note: I'd suggest you also clean up the dropdown lists so one cannot select two of the same and also cannot select Species..
answered Jan 1 at 14:28
blacktjblacktj
237
237
1
Unfortunately, this is not a good general strategy as facetting may create big problems and data may end up in the wrong facet. Use the appropriate non-standard evaluation, or useaes_
oraes_string
.
– Axeman
Jan 1 at 18:57
add a comment |
1
Unfortunately, this is not a good general strategy as facetting may create big problems and data may end up in the wrong facet. Use the appropriate non-standard evaluation, or useaes_
oraes_string
.
– Axeman
Jan 1 at 18:57
1
1
Unfortunately, this is not a good general strategy as facetting may create big problems and data may end up in the wrong facet. Use the appropriate non-standard evaluation, or use
aes_
or aes_string
.– Axeman
Jan 1 at 18:57
Unfortunately, this is not a good general strategy as facetting may create big problems and data may end up in the wrong facet. Use the appropriate non-standard evaluation, or use
aes_
or aes_string
.– Axeman
Jan 1 at 18:57
add a comment |