Add crosstalk examples for single and multiple dropdowns - #47
Add crosstalk examples for single and multiple dropdowns#47RyanDuffy01 wants to merge 8 commits into
Conversation
csillasch
left a comment
There was a problem hiding this comment.
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?
Moohan
left a comment
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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() |
There was a problem hiding this comment.
{DT} is already loaded.
| DT::datatable() | |
| datatable() |
| Person_Characteristics %>% | ||
| DT::datatable() |
There was a problem hiding this comment.
{DT} is already loaded.
| Person_Characteristics %>% | |
| DT::datatable() | |
| datatable(Person_Characteristics) |
| Person_And_Treatment_Lookup %>% | ||
| DT::datatable() |
There was a problem hiding this comment.
| Person_And_Treatment_Lookup %>% | |
| DT::datatable() | |
| datatable(Person_And_Treatment_Lookup) |
| All_BP_readings <- BP_Readings_treatment_1 %>% | ||
| rbind(BP_Readings_treatment_2) |
There was a problem hiding this comment.
No need for a pipe when we only have one function in the pipeline. Also using dplyr::bind_rows() instead of rbind()
| 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) |
| All_BP_readings <- All_BP_readings %>% | ||
| mutate(Identifier_Column = paste0(Person, "_", Treatment)) |
There was a problem hiding this comment.
| All_BP_readings <- All_BP_readings %>% | |
| mutate(Identifier_Column = paste0(Person, "_", Treatment)) | |
| All_BP_readings <- mutate(All_BP_readings, Identifier_Column = paste0(Person, "_", Treatment)) |
| example_data <- example_data %>% | ||
| crossing( | ||
| Hobbies = c("Badminton", "Chess") | ||
| ) |
There was a problem hiding this comment.
| example_data <- example_data %>% | |
| crossing( | |
| Hobbies = c("Badminton", "Chess") | |
| ) | |
| example_data <- crossing(example_data, Hobbies = c("Badminton", "Chess")) |
| Person_And_Treatment_Lookup <- All_BP_readings %>% | ||
| distinct(Person, Treatment, Identifier_Column) |
There was a problem hiding this comment.
| Person_And_Treatment_Lookup <- All_BP_readings %>% | |
| distinct(Person, Treatment, Identifier_Column) | |
| Person_And_Treatment_Lookup <- distinct(All_BP_readings, Person, Treatment, Identifier_Column) |
| $('#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); | ||
| }); |
There was a problem hiding this comment.
It seems to me like these could be combined?
| $('#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); | |
| }); |
No description provided.