Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

minor ui change #43

Merged
merged 2 commits into from
Jan 14, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Package: jsmodule
Title: 'RStudio' Addins and 'Shiny' Modules for Medical Research
Version: 1.6.1
Version: 1.6.2
Date: 2025-01-08
Authors@R: c(
person("Jinseob", "Kim", email = "jinseob2kim@gmail.com", role = c("aut", "cre"), comment = c(ORCID = "0000-0002-9403-605X")),
Expand Down
4 changes: 4 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# jsmodule 1.6.2
## Update
- Add options to customize x axis ticks in forest plot

# jsmodule 1.6.1
## Update
- Add function to allow adjusting cutoff for a single independent variable and observing model's metrics in `rocModule`, `rocModule2`.
Expand Down
61 changes: 49 additions & 12 deletions R/forestcox.R
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,10 @@ forestcoxUI <- function(id, label = "forestplot") {
uiOutput(ns("cov_tbsub")),
uiOutput(ns("time_tbsub")),
checkboxInput(ns("cmp_risk_check"), "Competing Risk Analysis(Fine-Gray)"),
uiOutput(ns("cmp_eventtime"))
uiOutput(ns("cmp_eventtime")),
checkboxInput(ns("custom_forest"), "Custom X axis ticks in forest plot"),
uiOutput(ns("hr_points")),
uiOutput(ns("numeric_inputs"))
)
}

Expand Down Expand Up @@ -246,13 +249,35 @@ forestcoxServer <- function(id, data, data_label, data_varStruct = NULL, nfactor

# print(cluster_id)

output$xlim_forest <- renderUI({
req(tbsub)
data <- tbsub()
data <- data[!(HR == 0 | Lower == 0)]$Upper
numericInput(session$ns("xMax"), "max HR for forestplot", value = round(max(as.numeric(data[data != "Inf"]), na.rm = TRUE), 2))


observeEvent(input$custom_forest, {
output$hr_points <-renderUI({
req(input$custom_forest == TRUE)
tagList(
sliderInput(session$ns("num_points"), "select number of x axis ticks", min = 2,max = 8,value = 3)
)
})
})

output$numeric_inputs <- renderUI({
req(input$num_points)
fluidRow(
lapply(seq_len(input$num_points), function(i) {
column(
width = floor(12 / input$num_points),
numericInput(
session$ns(paste0("point_", i)),
paste("Point", i, ":"),
value = 1.0
)
)
})
)
})



observeEvent(input$cmp_risk_check, {
output$cmp_eventtime <- renderUI({
req(input$cmp_risk_check == TRUE)
Expand Down Expand Up @@ -410,6 +435,20 @@ forestcoxServer <- function(id, data, data_label, data_varStruct = NULL, nfactor
})




ticks <- reactive({
if (is.null(input$num_points)) {
a <- c(0, 1, 2)
} else {
a <- sapply(seq_len(input$num_points), function(i) input[[paste0("point_", i)]])
}
return(a)
})




figure <- reactive({
group.tbsub <- input$group
label <- data_label()
Expand All @@ -430,8 +469,6 @@ forestcoxServer <- function(id, data, data_label, data_varStruct = NULL, nfactor
if (is.null(input$xMax) || any(is.na(xlim))) {
xlim <- c(0, 2)
}


forestploter::forest(data[, .SD, .SDcols = selected_columns],
lower = as.numeric(data$Lower),
upper = as.numeric(data$Upper),
Expand All @@ -440,8 +477,9 @@ forestcoxServer <- function(id, data, data_label, data_varStruct = NULL, nfactor
ref_line = 1,
ticks_digits = 1,
x_trans = "log",
xlim = xlim,
xlim = NULL,
arrow_lab = c(input$arrow_left, input$arrow_right),
ticks_at = ticks(),
theme = tm
) -> zz

Expand All @@ -451,6 +489,7 @@ forestcoxServer <- function(id, data, data_label, data_varStruct = NULL, nfactor
zz$heights[(l[1] - 2):(l[1] - 1)] <- h
return(zz)
})

res <- reactive({
list(
datatable(tbsub(),
Expand All @@ -463,13 +502,11 @@ forestcoxServer <- function(id, data, data_label, data_varStruct = NULL, nfactor
figure()
)
})

output$downloadControls <- renderUI({
tagList(
fluidRow(
column(
3,
uiOutput(session$ns("xlim_forest"))
), column(
3,
numericInput(session$ns("font"), "font-size", value = 12)
),
Expand Down
46 changes: 45 additions & 1 deletion R/forestglm.R
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,9 @@ forestglmUI <- function(id, label = "forestplot") {
uiOutput(ns("dep_tbsub")),
uiOutput(ns("subvar_tbsub")),
uiOutput(ns("cov_tbsub")),
checkboxInput(ns("custom_forest"), "Custom X axis ticks in forest plot"),
uiOutput(ns("beta_points")),
uiOutput(ns("numeric_inputs"))
)
}

Expand Down Expand Up @@ -378,6 +381,46 @@ forestglmServer <- function(id, data, data_label, family, data_varStruct = NULL,
return(tbsub)
})


observeEvent(input$custom_forest, {
output$beta_points <-renderUI({
req(input$custom_forest == TRUE)
tagList(
sliderInput(session$ns("num_points"), "select number of x axis ticks", min = 2,max = 8,value = 3)
)
})
})

output$numeric_inputs <- renderUI({
req(input$num_points)
fluidRow(
lapply(seq_len(input$num_points), function(i) {
column(
width = floor(12 / input$num_points),
numericInput(
session$ns(paste0("point_", i)),
paste("Point", i, ":"),
value = 1.0
)
)
})
)
})



ticks <- reactive({
if (is.null(input$num_points)) {
a <- c(0, 1, 2)
} else {
a <- sapply(seq_len(input$num_points), function(i) input[[paste0("point_", i)]])
}
return(a)
})




res <- reactive({
list(
datatable(tbsub(),
Expand Down Expand Up @@ -464,7 +507,8 @@ forestglmServer <- function(id, data, data_label, family, data_varStruct = NULL,
ref_line = ifelse(family == "gaussian", 0, 1),
x_trans = ifelse(family == "gaussian", "none", "log"),
ticks_digits = 1,
xlim = xlim,
xlim = NULL,
ticks_at = ticks(),
arrow_lab = c(input$arrow_left, input$arrow_right),
theme = tm
) -> zz
Expand Down
Loading