NB: I’ve read around quite a bit and it seems this Q has been asked before but the feature has not been implemented yet.
eg python - Plotly: How to remove unused values from x_axis - Stack Overflow
Also, I’m not interested in Shiny answers as I can’t use that at my university, so I’m making a static HTML dashboard that can be hosted on a local network drive
I have created a dashboard using r flexdashboard
where a Plotly
object is linked to a filterable and reactive DT
object. All works great except when I select data to show the Plotly
object does not drop the unused levels
There appears to be options to do this in Plotly.py
using x_axis_config
arguments but no such analogous feature in R plotly
I have also tried writing a python code chunk into my R markdown doc to make use of this feature but the r reticulate
package can’t work with a shared data frame created with r crosstalk
so you lose the interactive function between the plot, sidebar, and datatable
It seems like a fairly simple feature addition, no?
Sample Rmd:
title: "Test"
output:
flexdashboard::flex_dashboard:
orientation: rows
vertical_layout: scroll
theme: yeti
source_code: embed
#install.packages("flexdashboard")
#install.packages("DT")
#install.packages("plotly")
#install.packages("tidyverse")
#install.packages("ggpubr")
#install.packages("ggsci")
#install.packages("crosstalk")
library(flexdashboard)
library(DT)
library(plotly)
library(tidyverse)
library(ggpubr)
library(ggsci)
library(crosstalk)
AllResultsRaw <- as.data.frame(read.csv("CSVs/AllResultsCompiled.csv", header = TRUE, na.strings = c("NA", "n/a", "", "#DIV/0!"), strip.white = T))
AllResultsRaw <- tibble(AllResultsRaw)
AllResultsRaw <- unite(AllResultsRaw, Treatment, Concentration, col = "Condition", sep = "_")
AllResultsRaw <- AllResultsRaw %>% mutate(across(Cell.line, as.factor))
AllResultsRaw <- AllResultsRaw %>% mutate(across(Condition, as.factor))
shared_df <- SharedData$new(AllResultsRaw)
# Sidebar {.sidebar}
```{r}
filter_select("Condition", "Treatment", shared_df, ~Condition, multiple = T)
filter_checkbox("Cell line", "Cell line", shared_df, ~Cell.line, allLevels = F, inline = F)
Also, no feature here to have a select all/none checkbox - another request??
summaryColours2 = c('grey', 'cornflowerblue', 'blue', 'grey', 'brown1', 'firebrick3')
figure_1 <- plot_ly(shared_df, x = ~Donor,
y = ~BCD,
color = ~Condition,
colors = summaryColours2,
type = "bar")
figure_1
datatable(shared_df, filter = 'top')
Resulting graph does not drop the unused levels from the $Donor
factor column, resulting in large gaps