0

I am using plotly in R. What I want to do is to show a histogram and boxplot of the rent(v1030) of certain location. The plot can be changed by the the conditions input by several drop down menu in the crosstalk filters. (i.e.whether having Toilet, whether having Lift) When the drop down menu is showed, it include an option "(All)" at the top of the drop down menu. Keeping the (All) option to keep the entire database looks fine to me, but evreytime after I select a specific filter in the drop down menu (e.g. "Yes" in Toilet), when I click back to the (All) option in the drop down menu, the plot does not change (i.e. keep on filtered by "Yes" in Toilet). The plot changes normally when I swap through "Yes" and "No" in the drop down menu. The problem just happens when I select (All). Is there any solution for the problem? My code is as follows:

'''

library(plotly)
library(crosstalk)
library(dbplyr)
dataset$v1017 <- factor(dataset$v1017,levels = c(0,1),labels = c("No","Yes")) 
dataset$v1018 <- factor(dataset$v1018,levels = c(0,1),labels = c("No","Yes")) 
               
shareD<-SharedData$new(dataset)

p1<-shareD %>% plot_ly(x=~v1030)%>%add_histogram()%>%
layout(xaxis = list(dtick=1000,title = "Rent $"),yaxis = 
list(title="Frequency",fixedrange=TRUE))%>%config(displayModeBar = F)

p2<-shareD%>% plot_ly(y=~v1030,type="box",boxpoints=FALSE)%>%
layout(yaxis = list(dtick=1000,title = "Rent $"))%>%config(displayModeBar = F)

rentcaculator<-bscols(widths=c(3,NA),list(
filter_select(id = "lift", label = "Lift", multiple = FALSE,sharedData = shareSDU, group 
= ~v1018),
filter_select(id = "toilet", label = "Toilet", multiple = FALSE,sharedData = shareSDU, 
group = ~v1017),
p1,p2)

rentcaculator

'''

  • It looks like you're fairly new to SO; welcome to the community! If you want great answers quickly, it's best to make your question reproducible. This includes sample data like the output from `dput(head(dataObject)))` and any libraries you are using. Check it out: [making R reproducible questions](https://stackoverflow.com/q/5963269). – Kat Feb 23 '22 at 18:23

0 Answers0