I want to plot data in R, such that user can select which instances (which factor levels) to plot. I would like to do it using plotly and then host it using Shiny Server.
The problem is that I am getting every legend entry repeated twice after I update my selection (i.e. the first time it renders correctly, but after I click another variable to plot, the problem appears).
The weird part is that this problem is not present when running locally (e.g., inside R Studio or using runApp()
) or using shinyapps.io, but only when using Shiny Server.R
Is there a way to solve this and avoid duplicate entries?
Reproducible example:
library(plotly)
ui <- fluidPage(
fluidRow(
column(2,
checkboxGroupInput("species",
label = "Species",
choices = unique(iris$Species))),
column(10,
plotlyOutput('irisPlotly'))
)
)
server <- function(input, output) {
# Filter only selected species
selectedData <- reactive({
iris[iris$Species %in% input$species, ]
})
# Render plotly plot
output$irisPlotly <- renderPlotly({
plot_ly(selectedData(),
x = ~Sepal.Length,
y =~Sepal.Width,
color = ~Species) %>%
layout(showlegend = TRUE)
})
}
shinyApp(ui = ui, server = server)
Output of sessionInfo()
:
R version 3.3.2 (2016-10-31)
Platform: x86_64-pc-linux-gnu (64-bit)
Running under: Arch Linux
locale:
[1] LC_CTYPE=en_US.UTF-8 LC_NUMERIC=C
[3] LC_TIME=en_US.UTF-8 LC_COLLATE=en_US.UTF-8
[5] LC_MONETARY=en_US.UTF-8 LC_MESSAGES=en_US.UTF-8
[7] LC_PAPER=en_US.UTF-8 LC_NAME=C
[9] LC_ADDRESS=C LC_TELEPHONE=C
[11] LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C
attached base packages:
[1] stats graphics grDevices utils datasets methods base
other attached packages:
[1] plotly_4.5.6.9000 ggplot2_2.2.1.9000 shiny_1.0.0
loaded via a namespace (and not attached):
[1] Rcpp_0.12.9 magrittr_1.5 munsell_0.4.3 viridisLite_0.1.3
[5] colorspace_1.3-2 xtable_1.8-2 R6_2.2.0 httr_1.2.1
[9] plyr_1.8.4 dplyr_0.5.0 tools_3.3.2 grid_3.3.2
[13] gtable_0.2.0 DBI_0.5-1 crosstalk_1.0.0 htmltools_0.3.5
[17] yaml_2.1.14 lazyeval_0.2.0 digest_0.6.12 assertthat_0.1
[21] tibble_1.2 tidyr_0.6.1 purrr_0.2.2 base64enc_0.1-3
[25] htmlwidgets_0.8 mime_0.5 scales_0.4.1 jsonlite_1.3
[29] httpuv_1.3.3