Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Combining plotly with shiny causes plotly not to render in notebook #3535

Closed
RichardJActon opened this issue Sep 25, 2018 · 4 comments
Closed
Labels
bug reproducible stale Issues which have been closed automatically due to inactivitiy.

Comments

@RichardJActon
Copy link

Here is a reproducible example:
I initially had a problem when using ggplotly so checked if it was plotly more broardly.

If you run the chunks in Rstudio rather than Running the document the plot renders in the viewer so I'm thinking it might be related to issues #2748 and #2774 (see also plotly/plotly.R#717)


title: "ggplotly / Rstudio inline display bug"
author: "Richard J. Acton"
date: "2018-09-25"
output: html_notebook
runtime: shiny

library(tidyverse)
library(shiny)
library(plotly)
ui <- fluidPage(
	sidebarLayout(
		sidebarPanel(
			sliderInput(inputId = "threshold",
						label = "threshold",
						min = 0,
						max = 20,
						value = 5
						)
		),
	
		mainPanel(
			plotOutput(outputId = "scatterPlot")
		)
	)
)

server <- function(input, output) {
	data <- reactive({
		cars %>%
			filter(speed >= input$threshold)
	})
	
	# output$scatterPlot <- renderPlot({ 
	# 	ggplotly(
	# 	ggplot(data = data(),aes(speed,dist)) + 
	# 		geom_point() 
	# 	)
	# })
	
	output$scatterPlot <- renderPlot({ 
		plot_ly(data(), 
				x=~speed,
				y=~dist,
				type = 'scatter',
				mode = 'markers'
		)
	})
	
}

shinyApp(ui, server)

SessionInfo:

sessionInfo()
R version 3.4.4 (2018-03-15)
Platform: x86_64-pc-linux-gnu (64-bit)
Running under: Linux Mint 18.3

Matrix products: default
BLAS: /usr/lib/libblas/libblas.so.3.6.0
LAPACK: /usr/lib/lapack/liblapack.so.3.6.0

locale:
[1] LC_CTYPE=en_GB.UTF-8 LC_NUMERIC=C LC_TIME=en_GB.UTF-8 LC_COLLATE=en_GB.UTF-8
[5] LC_MONETARY=en_GB.UTF-8 LC_MESSAGES=en_GB.UTF-8 LC_PAPER=en_GB.UTF-8 LC_NAME=C
[9] LC_ADDRESS=C LC_TELEPHONE=C LC_MEASUREMENT=en_GB.UTF-8 LC_IDENTIFICATION=C

attached base packages:
[1] stats graphics grDevices utils datasets methods base

other attached packages:
[1] plotly_4.8.0.9000 bindrcpp_0.2.2 forcats_0.3.0 stringr_1.3.1 dplyr_0.7.6 purrr_0.2.5
[7] readr_1.1.1 tidyr_0.8.1 tibble_1.4.2 ggplot2_3.0.0 tidyverse_1.2.1 shiny_1.1.0

loaded via a namespace (and not attached):
[1] Rcpp_0.12.18 lubridate_1.7.4 lattice_0.20-35 assertthat_0.2.0 rprojroot_1.3-2 digest_0.6.17
[7] mime_0.5 R6_2.2.2 cellranger_1.1.0 plyr_1.8.4 backports_1.1.2 evaluate_0.11
[13] httr_1.3.1 pillar_1.3.0 rlang_0.2.2 curl_3.2 lazyeval_0.2.1 readxl_1.1.0
[19] rstudioapi_0.7 data.table_1.11.6 rmarkdown_1.10 labeling_0.3 devtools_1.13.6 htmlwidgets_1.2
[25] munsell_0.5.0 broom_0.5.0 compiler_3.4.4 httpuv_1.4.5 modelr_0.1.2 pkgconfig_2.0.2
[31] base64enc_0.1-3 htmltools_0.3.6 tidyselect_0.2.4 viridisLite_0.3.0 crayon_1.3.4 withr_2.1.2
[37] later_0.7.4 grid_3.4.4 nlme_3.1-137 jsonlite_1.5 xtable_1.8-3 gtable_0.2.0
[43] git2r_0.23.0 magrittr_1.5 scales_1.0.0 cli_1.0.0 stringi_1.2.4 promises_1.0.1
[49] xml2_1.2.0 tools_3.4.4 Cairo_1.5-9 glue_1.3.0 hms_0.4.2 crosstalk_1.0.0
[55] yaml_2.2.0 colorspace_1.3-2 rvest_0.3.2 memoise_1.1.0 knitr_1.20 bindr_0.1.1
[61] haven_1.1.2

@ronblum
Copy link
Contributor

ronblum commented Nov 20, 2018

Confirmed on MacOS 10.14 Mojave.

@RichardJActon
Copy link
Author

I realise that I used the wrong render/output functions in the above example, plotlyOutput and renderPlotly produce an inline plot in the resulting notebook as expected (see below). It might be a good idea to have some kind of type check on the renderPlot / plotOutput functions that warns if a plotly object is passed rather than short-of failing silently?

ui <- fluidPage(
	sidebarLayout(
		sidebarPanel(
			sliderInput(inputId = "threshold",
						label = "threshold",
						min = 0,
						max = 20,
						value = 5
						)
		),
	
		mainPanel(
			plotlyOutput(outputId = "scatterPlot")
		)
	)
)
server <- function(input, output) {
	data <- reactive({
		cars %>%
			filter(speed >= input$threshold)
	})
	
	# output$scatterPlot <- renderPlotly({ 
	# 	ggplotly(
	# 	ggplot(data = data(),aes(speed,dist)) + 
	# 		geom_point() 
	# 	)
	# })
	
	output$scatterPlot <- renderPlotly({ 
		plot_ly(data(), 
				x=~speed,
				y=~dist,
				type = 'scatter',
				mode = 'markers'
		)
	})
	
}

shinyApp(ui, server)

@stale
Copy link

stale bot commented Feb 6, 2021

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs, per https://github.com/rstudio/rstudio/wiki/Issue-Grooming. Thank you for your contributions.

@stale stale bot added the stale Issues which have been closed automatically due to inactivitiy. label Feb 6, 2021
@stale
Copy link

stale bot commented Feb 20, 2021

This issue has been automatically closed due to inactivity.

@stale stale bot closed this as completed Feb 20, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug reproducible stale Issues which have been closed automatically due to inactivitiy.
Projects
None yet
Development

No branches or pull requests

2 participants