Shiny Flashcards

(25 cards)

1
Q

What is the purpose of reactive decorators in Shiny?

A

Reactive decorators (like @reactive.Calc, @reactive.Effect, @reactive.event) are used to mark functions as reactive — meaning Shiny will automatically track their dependencies and re-run them whenever those dependencies change.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

difference between @reactive.Calc and @reactive.Effect

A

@reactive.Calc → returns a value, caches it, and re-runs only when its dependencies change. Used when you need the result elsewhere (like data for a plot).

@reactive.Effect → performs an action, doesn’t return a value, and re-runs when dependencies change. Used for side effects (logging, writing files, showing a message)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What is reactive programming in Shiny?

A

A dependency graph causes outputs to automatically update when inputs change.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

How to create an input element in Shiny Express?

A

Use ui functions like ui.input_select(id, label, choices, selected).

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

How to access an input value?

A

Use input.<id>(), e.g., input.selectBox1().</id>

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

How to create a reactive output?

A

Decorate a function with @render.<type>, e.g., @render.text or @render.plot.</type>

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

What must a reactive function return?

A

An object of the type corresponding to its decorator, e.g. text, plot, or data frame.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

What are @render._ decorators used for?

A

They create UI output elements using the return value of the decorated function.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

What is @reactive.calc used for?

A

Defines a reactive computation whose result can be reused in other reactive functions to avoid duplication.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

What is @reactive.effect used for?

A

Triggers side effects when inputs change but returns no value.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

What is @reactive.event(*args) used for?

A

Makes a function react only to specified dependencies.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

What does reactive.value() create?

A

A reactive object that other reactive functions can depend on, similar to input.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

Name some Shiny layout options.

A

Sidebar layout, Navbars, Tabs, Panels/Cards.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

How to structure UI containers in Shiny Core?

A

Using nested function calls, e.g. ui.sidebar(ui.input_text()).

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

How to structure UI containers in Shiny Express?

A

Using Python context managers (with statements).

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

Main code organization difference between Express and Core?

A

Express places outputs implicitly; Core requires explicit UI output element definitions linked to reactive functions.

17
Q

Advantages of Core’s explicit output placement?

A

Easier to rearrange UI and to pass additional parameters to output elements.

18
Q

Difference in import statements between Core and Express?

A

Express:
from shiny.express import input, render, ui.

Core:
from shiny import App, render, ui.

19
Q

How can you run a Shiny app locally?

A

shiny run –reload –launch-browser –port=0 app.py

or
via VS Code extension.

20
Q

Name some Shiny deployment options.

A

Posit Cloud (shinyapps.io), Hugging Face Spaces, Shinylive, or your own server with Shiny Server.

21
Q

How does Shiny compare to Streamlit?

A

Shiny offers fully automatic reactivity and CSS/JS-based layouts; Streamlit is simpler but less reactive.

22
Q

How does Shiny compare to Dash?

A

Dash is more flexible but requires manual callbacks; Shiny is easier for automatic reactivity.

23
Q

How does Shiny compare to tkinter?

A

tkinter is for desktop apps only and lacks web deployment options.

24
Q

What does it mean to “invalidate” a dependency in Shiny?

A

a) a reactive value has changed
b) an input has changed

25
What is a "reactive dependency" in Shiny?
Anything (like an input or another reactive value) that a reactive expression depends on. When one of these dependencies changes, Shiny invalidates all dependent expressions. Invalidating means marking them as “out of date” so they will re-run the next time their value is needed.