Conditional chunk for python quarto docs #12026
-
DescriptionIs it possible to conditionally evaluate a chunk based on an environment variable in python quarto docs? You can include content conditionally really nicely in R a la:
I didn't expect the following to work but I wanted to share to illustrate the type of thing I am doing. I see this section on conditional content but I think that is restricted to output type. My exact use case is wanting to not evaluate some chunks when I publish something to confluence hence wanting to evaluate on a environment variable:
That fails with this error:
|
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 6 replies
-
Unless you have a burning need for the conditional execution logic to not show up in your final output, I feel like it might just be easier to put that logic in the chunk itself:
|
Beta Was this translation helpful? Give feedback.
-
Jupyter does not have a similar feature. So, two options:
|
Beta Was this translation helpful? Give feedback.
-
I also needed this. I came up with an alternative solution - use inline code expressions with inline ---
format: html
---
```{python}
#| include: false
from IPython.display import Markdown
```
```{python}
hide_some_things = True
```
`{python} Markdown("::: {.content-hidden}") if hide_some_things else None`
```{python}
print("Hidden")
```
`{python} Markdown(":::") if hide_some_things else None`
```{python}
print("Shown")
``` It will be great when this feature is added to Quarto. |
Beta Was this translation helpful? Give feedback.
Unless you have a burning need for the conditional execution logic to not show up in your final output, I feel like it might just be easier to put that logic in the chunk itself: