Interactive Storytelling with Shiny
2025-04-09
No
Nope
Jamás
Regla de Storytelling #1
Nunca reveles el final antes de tiempo.
Siempre eleva la tensión y el dramatismo
Data Storytelling
¿Por qué Data Storytelling?
🔥 Las historias son la primera tecnología humana
Regla del máximo y final (Peak-End Rule)
Rating de Game of Thrones, por Kelvin Neo
Usar trucos de Storytelling (narrativa) para crear presentaciones que serán recordadas y que causarán impacto
🎭 Las emociones generan acciones
¿Podemos hacer que millones de personas compartan estadísticas en redes sociales?
Regla de Storytelling #2
Los detalles son importantes, pero no todos los detalles son importantes.
🔢 No compartas números
🪶Comparte una historia
(C) Storytelling with Data, por Cole Nussbaumer Knaflic.
Regla de Storytelling #3
Tu primera versión siempre será horrible.
🥱 1° versión \(<\) … \(<\) 😊 última versión
Regla de Storytelling #4
Explicar menos y mostrar más
Quarto es un sistema abierto para publicaciones científicas con markdown y código interactivo (Python/R).
Código: example.qmd
---
title: "Habits"
author: "John Doe"
format:
revealjs:
transition: fade
theme: black
toc: true
center: true
---
## Getting up
- Turn off alarm
- Get out of bed
---
## Going to sleep
::: { .incremental }
- Get in bed
- Count sheep
:::
Slides: example.html
Las extensiones son una herramienta poderosa para modificar y ampliar el comportamiento de Quarto.
Shiny es un paquete de R que permite crear aplicaciones web interactivas fácilmente usando R (También disponible para python).
Código para desplegar aplicaciones Shiny que se ejecutarán completamente en el navegador, utilizando Pyodide y webR (Python y R compilados a WebAssembly).
R: Ejemplos de Shinylive en R
Python: Ejemplos de Shinylive en Python
#| '!! shinylive warning !!': |
#| shinylive does not work in self-contained HTML documents.
#| Please set `embed-resources: false` in your metadata.
#| standalone: true
#| viewerHeight: 550
from shiny import App, ui, render, reactive
import matplotlib.pyplot as plt
import io
import base64
# Function to generate the plot dynamically based on input values
def create_plot(yes_value, no_value):
categories = ['Yes', 'No']
values = [yes_value, no_value]
fig, ax = plt.subplots(figsize=(10, 3))
ax.bar(categories, values, color=['lightblue', 'salmon'])
ax.set_title('😊 Do you like the presentation so far? 😊')
# Convert the image to base64 for display in Shiny
buf = io.BytesIO()
plt.savefig(buf, format="png")
plt.close(fig)
buf.seek(0)
encoded_image = base64.b64encode(buf.getvalue()).decode()
return f'<img src="data:image/png;base64,{encoded_image}" style="max-width:100%;">'
# UI definition
app_ui = ui.page_fluid(
ui.h2("Interactive Survey"),
# Sliders to change values dynamically
ui.input_slider("yes_value", "Yes responses:", min=0, max=50, value=20),
ui.input_slider("no_value", "No responses:", min=0, max=50, value=10),
# Output area for the plot
ui.output_ui("plot_output")
)
# Server function
def server(input, output, session):
@output
@render.ui
def plot_output():
return ui.HTML(create_plot(input.yes_value(), input.no_value()))
# Create the Shiny app
app = App(app_ui, server)
🔗 Nuestro Sitio Web: seth-nut.github.io/resources.