apizzichini commited on
Commit
0ee3f96
·
verified ·
1 Parent(s): 19945b2

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +14 -4
app.py CHANGED
@@ -1,6 +1,6 @@
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",
@@ -18,6 +18,9 @@ juego = {
18
 
19
  pais_actual = "Argentina"
20
 
 
 
 
21
  # Interfaz
22
  app_ui = ui.page_fluid(
23
  ui.h2("🎮 Juego: Adiviná el país"),
@@ -25,10 +28,11 @@ app_ui = ui.page_fluid(
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
@@ -36,12 +40,18 @@ def server(input, output, session):
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)
 
 
1
  from shiny import App, ui, render, reactive
2
 
3
+ # Diccionario del juego
4
  juego = {
5
  "Argentina": {
6
  "pista": "País sudamericano con mate y fútbol",
 
18
 
19
  pais_actual = "Argentina"
20
 
21
+ # Estado reactivo para el resultado
22
+ resultado_estado = reactive.Value("")
23
+
24
  # Interfaz
25
  app_ui = ui.page_fluid(
26
  ui.h2("🎮 Juego: Adiviná el país"),
 
28
  ui.output_text("pista"),
29
  ui.input_text("respuesta", "Tu respuesta"),
30
  ui.input_action_button("verificar", "Verificar"),
31
+ ui.hr(),
32
  ui.output_text("resultado")
33
  )
34
 
35
+ # Servidor
36
  def server(input, output, session):
37
 
38
  @output
 
40
  def pista():
41
  return juego[pais_actual]["pista"]
42
 
43
+ @output
44
+ @render.text
45
+ def resultado():
46
+ return resultado_estado()
47
+
48
  @reactive.effect
49
  @reactive.event(input.verificar)
50
  def verificar_respuesta():
51
  if input.respuesta().lower() == juego[pais_actual]["respuesta"]:
52
+ resultado_estado.set("✅ Correcto!")
53
  else:
54
+ resultado_estado.set(f"❌ Incorrecto. Era {pais_actual}")
55
 
56
  app = App(app_ui, server)
57
+