hanta

Author

tortosa

Quarto

Quarto enables you to weave together content and executable code into a finished document. To learn more about Quarto see https://quarto.org.

Running Code

When you click the Render button a document will be generated that includes both content and the output of embedded code. You can embed code like this:

1 + 1
[1] 2

You can add options to executable code like this

library(shiny)

# Definición de los pesos normalizados para cada factor pronóstico
weights <- c(AgeOver40 = 0.178, FemaleGender = 0.048, HematocritOver42 = 0.166,
             IncreasedCreatinine = 0.108, ChestInfiltrates = 0.419, Vomiting = -0.082)

# Umbral para el 20% del valor máximo
threshold_low_risk <- 1.319 * 0.20

# UI
ui <- fluidPage(
  titlePanel("Calculadora de Riesgo de Mortalidad por Hantavirus"),
  sidebarLayout(
    sidebarPanel(
      checkboxInput("ageOver40", "Mayor de 40 años", value = FALSE),
      checkboxInput("femaleGender", "Género femenino", value = FALSE),
      checkboxInput("hematocritOver42", "Hematocrito mayor de 42%", value = FALSE),
      checkboxInput("increasedCreatinine", "Creatinina aumentada (>1.4 mg/dl)", value = FALSE),
      checkboxInput("chestInfiltrates", "Infiltrados en radiografía de tórax", value = FALSE),
      checkboxInput("vomiting", "Presencia de vómitos", value = FALSE),
      actionButton("calculate", "Calcular Puntaje de Riesgo")
    ),
    mainPanel(
      textOutput("result"),
      textOutput("references"),
      textOutput("guidance")
    )
  )
)

# Server logic
server <- function(input, output) {
  observeEvent(input$calculate, {
    # Seleccionar factores con base en las entradas del usuario
    factors <- names(weights)[as.logical(c(input$ageOver40, input$femaleGender, 
                                           input$hematocritOver42, input$increasedCreatinine, 
                                           input$chestInfiltrates, input$vomiting))]
    # Calcular el puntaje sumando los pesos correspondientes
    score <- sum(weights[factors])
    
    # Definir los niveles de riesgo según el puntaje
    risk_level <- ifelse(score <= threshold_low_risk, 
                         "Bajo Riesgo - Evaluar periódicamente por signos concurrentes de alarma.",
                         "Alto Riesgo - Requiere atención médica inmediata.")
    
    output$result <- renderText({
      sprintf("Tu puntaje de riesgo calculado es: %.3f, correspondiente a: %s\nUn mayor puntaje indica un peor pronóstico.", score, risk_level)
    })
    
    output$references <- renderText({
      "Referencias:\n1. Darzi AJ, Karam SG, Spencer FA, et al. Risk models for VTE and bleeding in medical inpatients: systematic identification and expert assessment. Blood Advances 2020; 4: 2557–66.\n2. Darzi AJ, Karam SG, Charide R, et al. Prognostic factors for VTE and bleeding in hospitalized medical patients: a systematic review and meta-analysis. Blood 2020; 135: 1788–810.\n3. Tortosa y cols. Prognostic factors for mortality in patients infected with hantavirus: A systematic review."
    })
    
    output$guidance <- renderText({
      "Guía de uso del puntaje:\nEl puntaje calculado te ayuda a entender el nivel de riesgo de mortalidad debido a la infección por hantavirus. Un puntaje bajo indica la necesidad de vigilancia periódica, mientras que un puntaje alto sugiere la necesidad de intervenciones médicas más intensivas."
    })
  })
}

# Run the application 
shinyApp(ui = ui, server = server)

Shiny applications not supported in static R Markdown documents

2 * 2

The echo: false option disables the printing of code (only output is displayed).