Reputation: 397
I'm creating a markdown document with embeded ggvis charts. When uploading these charts to ggvis the field remains blank until the black corner of the graph is moved. At that point the graph starts showing.
How can I make sure the graph is showing from the start?
The following coded is used to generate the graphs:
train%>% ggvis(~Survived, opacity := 0.8, fill:= "firebrick") %>%
layer_bars() %>%
set_options(width =300, height =300) %>%
add_axis("x", title = "Non-survivors versus Survivors")
The graph is situated in element 2.2.
Thank you in advance.
EDIT:
Based on the input I received in the comments I made the following adjustments:
```{r echo = FALSE}
train%>% ggvis(~Survived, opacity := 0.8, fill:= "firebrick") %>%
layer_bars() %>%
set_options(width =300, height =300) %>%
add_axis("x", title = "Non-survivors versus Survivors") %>%
bind_shiny("PlotSurvived")
```
```{r echo = FALSE}
ggvisOutput("PlotSurvived")
```
The result is that the application tries to load the graph twice. Once for the first code chunk. In this case the problem remains the same.
The second code chunk load successfully.
An additional question rises:
How can I create the graph without displaying it in chunck one? And the using ggvisOutput("PlotSurvived")
to display it?
Would this be the best practice?
Kind regards
Upvotes: 1
Views: 124
Reputation: 397
Based on the comments and guidelines provided by user10853 I managed to created a 'dirty' workaround. The solution that worked in my case can be found below.
{r, echo = FALSE, results = "hide"}
train%>% ggvis(~Survived, opacity := 0.8, fill:= "firebrick") %>%
layer_bars() %>%
set_options(width =300, height =300) %>%
add_axis("x", title = "Non-survivors versus Survivors") %>%
bind_shiny("PlotSurvived")
By setting echo = FALSE
R Markdown will not display the code in the final document (but it will still run the code and display its results unless told otherwise). This is what you need in order to make sure the plot gets generated within the code and that the bind_shiny()
element get executed.
By setting result = FALSE
R Markdown will not display the results of the code (but it will still run the code and display the code itself unless told otherwise).
This means echo
ensures the code does not get displayed while result
ensures the 'broken' graph doesn't gets displayed.
I follow up with this piece of code in order to generate the working graph.
```{r echo = FALSE}
ggvisOutput("PlotSurvived")
```
Upvotes: 1
Reputation: 302
It shows just fine. I just viewed it in my phone. Maybe it's your browser?
Update: I just checked it in Chrome and it is as your report. Try setting the dimensions of the graph manually.
Upvotes: 0