Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,15 +1,47 @@
|
|
| 1 |
-
from shiny import App, ui, render
|
| 2 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3 |
app_ui = ui.page_fluid(
|
| 4 |
-
ui.h2("
|
| 5 |
-
ui.
|
|
|
|
|
|
|
|
|
|
| 6 |
ui.output_text("resultado")
|
| 7 |
)
|
| 8 |
|
|
|
|
| 9 |
def server(input, output, session):
|
|
|
|
| 10 |
@output
|
| 11 |
@render.text
|
| 12 |
-
def
|
| 13 |
-
return
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 14 |
|
| 15 |
app = App(app_ui, server)
|
|
|
|
| 1 |
+
from shiny import App, ui, render, reactive
|
| 2 |
|
| 3 |
+
# Diccionario del juego (EL MISMO)
|
| 4 |
+
juego = {
|
| 5 |
+
"Argentina": {
|
| 6 |
+
"pista": "País sudamericano con mate y fútbol",
|
| 7 |
+
"respuesta": "argentina"
|
| 8 |
+
},
|
| 9 |
+
"Brasil": {
|
| 10 |
+
"pista": "País sudamericano famoso por el carnaval",
|
| 11 |
+
"respuesta": "brasil"
|
| 12 |
+
},
|
| 13 |
+
"Japón": {
|
| 14 |
+
"pista": "País asiático con trenes bala",
|
| 15 |
+
"respuesta": "japon"
|
| 16 |
+
}
|
| 17 |
+
}
|
| 18 |
+
|
| 19 |
+
pais_actual = "Argentina"
|
| 20 |
+
|
| 21 |
+
# Interfaz
|
| 22 |
app_ui = ui.page_fluid(
|
| 23 |
+
ui.h2("🎮 Juego: Adiviná el país"),
|
| 24 |
+
ui.p("Pista:"),
|
| 25 |
+
ui.output_text("pista"),
|
| 26 |
+
ui.input_text("respuesta", "Tu respuesta"),
|
| 27 |
+
ui.input_action_button("verificar", "Verificar"),
|
| 28 |
ui.output_text("resultado")
|
| 29 |
)
|
| 30 |
|
| 31 |
+
# Lógica del servidor
|
| 32 |
def server(input, output, session):
|
| 33 |
+
|
| 34 |
@output
|
| 35 |
@render.text
|
| 36 |
+
def pista():
|
| 37 |
+
return juego[pais_actual]["pista"]
|
| 38 |
+
|
| 39 |
+
@reactive.effect
|
| 40 |
+
@reactive.event(input.verificar)
|
| 41 |
+
def verificar_respuesta():
|
| 42 |
+
if input.respuesta().lower() == juego[pais_actual]["respuesta"]:
|
| 43 |
+
output.resultado.set("✅ Correcto!")
|
| 44 |
+
else:
|
| 45 |
+
output.resultado.set(f"❌ Incorrecto. Era {pais_actual}")
|
| 46 |
|
| 47 |
app = App(app_ui, server)
|