Skip to content

Add crosstalk examples for single and multiple dropdowns - #47

Open
RyanDuffy01 wants to merge 8 commits into
mainfrom
crosstalk_example
Open

Add crosstalk examples for single and multiple dropdowns#47
RyanDuffy01 wants to merge 8 commits into
mainfrom
crosstalk_example

Conversation

@RyanDuffy01

Copy link
Copy Markdown

No description provided.

@RyanDuffy01
RyanDuffy01 requested review from Moohan and csillasch July 8, 2026 09:11

@csillasch csillasch left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Clear to follow and runs okay, have just marked a few typos and wording in comments to fix. Unsure if the example within the example explaining crossing is required?

Comment thread RMarkdown/Crosstalk/Multiple Dropdowns Crosstalk Example.Rmd Outdated
Comment thread RMarkdown/Crosstalk/One Dropdown CrossTalk Example.Rmd Outdated
Comment thread RMarkdown/Crosstalk/One Dropdown CrossTalk Example.Rmd Outdated
Comment thread RMarkdown/Crosstalk/One Dropdown CrossTalk Example.Rmd Outdated
Comment thread RMarkdown/Crosstalk/Multiple Dropdowns Crosstalk Example.Rmd Outdated
Comment thread RMarkdown/Crosstalk/Multiple Dropdowns Crosstalk Example.Rmd Outdated
Comment thread RMarkdown/Crosstalk/Multiple Dropdowns Crosstalk Example.Rmd Outdated
Comment thread RMarkdown/Crosstalk/Multiple Dropdowns Crosstalk Example.Rmd Outdated
Comment thread RMarkdown/Crosstalk/Multiple Dropdowns Crosstalk Example.Rmd Outdated
Comment thread RMarkdown/Crosstalk/Multiple Dropdowns Crosstalk Example.Rmd Outdated

@Moohan Moohan left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lots of style changes suggested! I would also prefer the base pipe |> over magrittr %>% nowadays, since we're guaranteed to be using an R version that has it.

library(flexdashboard)
library(DT)
library(bsplus)
library(tidyverse)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd always prefer to load the specific tidyverse packages needed instead of library(tidyverse), especially in an example script.

library(flexdashboard)
library(DT)
library(bsplus)
library(tidyverse)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd always prefer to load the specific tidyverse packages needed instead of library(tidyverse), especially in an example script.

# Now our data looks like this
All_BP_readings %>%
mutate(BP = round(BP)) %>%
DT::datatable()

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

{DT} is already loaded.

Suggested change
DT::datatable()
datatable()

Comment on lines +126 to +127
Person_Characteristics %>%
DT::datatable()

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

{DT} is already loaded.

Suggested change
Person_Characteristics %>%
DT::datatable()
datatable(Person_Characteristics)

Comment on lines +148 to +149
Person_And_Treatment_Lookup %>%
DT::datatable()

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Person_And_Treatment_Lookup %>%
DT::datatable()
datatable(Person_And_Treatment_Lookup)

Comment on lines +62 to +63
All_BP_readings <- BP_Readings_treatment_1 %>%
rbind(BP_Readings_treatment_2)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No need for a pipe when we only have one function in the pipeline. Also using dplyr::bind_rows() instead of rbind()

Suggested change
All_BP_readings <- BP_Readings_treatment_1 %>%
rbind(BP_Readings_treatment_2)
All_BP_readings <- bind_rows(BP_Readings_treatment_1, BP_Readings_treatment_2)

Comment on lines +72 to +73
All_BP_readings <- All_BP_readings %>%
mutate(Identifier_Column = paste0(Person, "_", Treatment))

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
All_BP_readings <- All_BP_readings %>%
mutate(Identifier_Column = paste0(Person, "_", Treatment))
All_BP_readings <- mutate(All_BP_readings, Identifier_Column = paste0(Person, "_", Treatment))

Comment on lines +109 to +112
example_data <- example_data %>%
crossing(
Hobbies = c("Badminton", "Chess")
)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
example_data <- example_data %>%
crossing(
Hobbies = c("Badminton", "Chess")
)
example_data <- crossing(example_data, Hobbies = c("Badminton", "Chess"))

Comment on lines +143 to +144
Person_And_Treatment_Lookup <- All_BP_readings %>%
distinct(Person, Treatment, Identifier_Column)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Person_And_Treatment_Lookup <- All_BP_readings %>%
distinct(Person, Treatment, Identifier_Column)
Person_And_Treatment_Lookup <- distinct(All_BP_readings, Person, Treatment, Identifier_Column)

Comment on lines +278 to +295
$('#dashboard-container').on('flexdashboard:layoutcomplete', function() {

// Select Person filter and remove (all) option
$('#person .selectized')[0].selectize.removeOption("");

// Select Person filter and set its default value on load to Person A
$('#person .selectized')[0].selectize.setValue("A", false);
});

// Called when flexdashboard content has been created. Won't work properly otherwise
$('#dashboard-container').on('flexdashboard:layoutcomplete', function() {

// Select Treatment filter and remove (all) option
$('#treatment .selectized')[0].selectize.removeOption("");

// Select Treatment filter and set its default value on load to Heart Medication 1
$('#treatment .selectized')[0].selectize.setValue("Heart Medication 1", false);
});

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems to me like these could be combined?

Suggested change
$('#dashboard-container').on('flexdashboard:layoutcomplete', function() {
// Select Person filter and remove (all) option
$('#person .selectized')[0].selectize.removeOption("");
// Select Person filter and set its default value on load to Person A
$('#person .selectized')[0].selectize.setValue("A", false);
});
// Called when flexdashboard content has been created. Won't work properly otherwise
$('#dashboard-container').on('flexdashboard:layoutcomplete', function() {
// Select Treatment filter and remove (all) option
$('#treatment .selectized')[0].selectize.removeOption("");
// Select Treatment filter and set its default value on load to Heart Medication 1
$('#treatment .selectized')[0].selectize.setValue("Heart Medication 1", false);
});
$('#dashboard-container').on('flexdashboard:layoutcomplete', function() {
// Select Person filter and remove (all) option
$('#person .selectized')[0].selectize.removeOption("");
// Select Person filter and set its default value on load to Person A
$('#person .selectized')[0].selectize.setValue("A", false);
// Select Treatment filter and remove (all) option
$('#treatment .selectized')[0].selectize.removeOption("");
// Select Treatment filter and set its default value on load to Heart Medication 1
$('#treatment .selectized')[0].selectize.setValue("Heart Medication 1", false);
});

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants