Parameters in Rmarkdown for interactive filtering in an R chunk

Hello, I am trying to pass parametrically (in the YAML metadata) the option of filtering a dataset by choosing a specific argument (from YAML "params" ) for the "filter" function.

When I run the code i get an empty table for "my_titanic". When I run the same code in R with this filter --> filter(Class== "parameter1" | Class=="parameter2") works perfectly and I get the filtered "my_titanic" table.

Any idea what am I doing wrong? Any help will be more than welcome.

---
date: "`r Sys.Date()`"
output:
  html_document: default

params:
parameter1:
    label: 'Parameter 1:'
    value: First
    input: select
    choices:
    - 'First'
    - 'Second'
    - 'Third' 
  parameter2:
    label: 'Parameter 2:'
    value: Second
    input: select
    choices:
    - 'First'
    - 'Second'
    - 'Third'   
 data:
    label: 'Input dataset:'
    value: sample.csv
    input: file
---

```{r setup, echo=FALSE,  message=FALSE}
library(readr)
library(dplyr)
library(ggplot2)
library(datasets)

parameter1 <- params$parameter1
parameter2 <- params$parameter2
dedomena <- params$data
c_Titanic <- read.table(dedomena, sep=",", header=TRUE, stringsAsFactors = FALSE)
my_titanic <- c_Titanic %>% filter(Class== "parameter1" | Class=="parameter2")
```

Hi,

I edited your code to format correctly. Can you check the YAML content ?
It does not seem complete so can you edit and share the YAML header as you set it ?

Thank you

Hi!
thank you so much for your feedback. It is my first post here! I'll add the rest of the YAML header and share it.

Are you sure about the double quote here ?

This seems good and each should be character string based on your param. So I don't think they should be quoted in the filter function.

I am surprised you said the code works when executed interactively.

1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.