英文:
R Shiny RenderUI output formatting issue: removing an html text and reforming the appearances
问题
以下是您的R Shiny代码的翻译部分:
library(tidyverse)
library(shiny)
library(shinythemes)
library(data.table)
library(ggplot2)
library(GGally)
main_page <- tabPanel(
title = "Analysis",
titlePanel("Analysis"),
sidebarLayout(
sidebarPanel(
title = "Inputs",
fileInput("csv_input", "Select CSV File to Import", accept = ".csv"),
selectInput("site_var", "1. Identify the site variable", choices = NULL),
selectInput("s_cov", "2. Select covariates", choices = NULL, multiple = TRUE),
strong("3. Impose constraints:"), actionButton("constraintBtn", "", icon = icon("circle-plus"), class="btn btn-link"),
uiOutput("constraintInputs"),
actionButton("run_button", "Run Analysis", icon = icon("play"), class = "btn-primary")
),
mainPanel(
tabsetPanel(
tabPanel(
title = "Plot",
plotOutput("s_plot")
),
)
)
)
)
ui <- navbarPage(
title = "Synthetic Purposive Sampling",
theme = shinytheme('flatly'),
main_page
)
server <- function(input, output){
options(shiny.maxRequestSize=10*1024^2)
data_input <- reactive({
req(input$csv_input)
read.csv(input$csv_input$datapath)
})
observeEvent(data_input(),{
choices <- c(names(data_input()))
choices_numeric <- c(names(data_input() %>% select(is.numeric)))
updateSelectInput(inputId = "site_var", choices = choices)
updateSelectInput(inputId = "s_cov", choices = choices_numeric)
})
constraints <- reactiveValues(inputs = list())
observeEvent(input$constraintBtn, {
constraints$inputs <- c(constraints$inputs, list(
column(4, selectInput(paste0("var_", length(constraints$inputs) + 1), "Var:", choices = input$s_cov)),
column(4, selectInput(paste0("txt_", length(constraints$inputs) + 1), "Condition:", choices = c("<", ">"), selected = NULL)),
column(4, numericInput(paste0("val_", length(constraints$inputs) + 1), "Value:", value = NULL))
))
})
output$constraintInputs <- renderUI({
if (length(constraints$inputs) > 0){
lapply(constraints$inputs, function(x){
fluidRow(x[[1]], x[[2]], x[[3]])
})
}
})
s_plot <- eventReactive(input$run_button,{
ggpairs(data = data_input(), columns = c(input$s_cov))
})
output$s_plot <- renderPlot(s_plot())
}
shinyApp(ui = ui, server = server)
希望这对您有所帮助。如果您有其他问题,请随时提问。
英文:
I have a following R shiny code:
library(tidyverse)
library(shiny)
library(shinythemes)
library(data.table)
library(ggplot2)
library(GGally)
main_page <- tabPanel(
title = "Analysis",
titlePanel("Analysis"),
sidebarLayout(
sidebarPanel(
title = "Inputs",
fileInput("csv_input", "Select CSV File to Import", accept = ".csv"),
selectInput("site_var", "1. Identify the site variable", choices = NULL),
selectInput("s_cov", "2. Select covariates", choices = NULL, multiple = T),
strong("3. Impose constraints:"), actionButton("constraintBtn", "", icon = icon("circle-plus"), class="btn btn-link"),
uiOutput("constraintInputs"),
actionButton("run_button", "Run Analysis", icon = icon("play"), class = "btn-primary")
),
mainPanel(
tabsetPanel(
tabPanel(
title = "Plot",
plotOutput("s_plot")
),
)
)
)
)
ui <- navbarPage(
title = "Synthetic Purposive Sampling",
theme = shinytheme('flatly'),
main_page
)
server <- function(input, output){
options(shiny.maxRequestSize=10*1024^2)
data_input <- reactive({
req(input$csv_input)
read.csv(input$csv_input$datapath)
})
observeEvent(data_input(),{
choices <- c(names(data_input()))
choices_numeric <- c(names(data_input() %>% select(is.numeric)))
updateSelectInput(inputId = "site_var", choices = choices)
updateSelectInput(inputId = "s_cov", choices = choices_numeric)
})
constraints <- reactiveValues(inputs = list())
observeEvent(input$constraintBtn, {
constraints$inputs <- c(constraints$inputs, list(
column(4, selectInput(paste0("var_", length(constraints$inputs) + 1), "Var:", choices = input$s_cov)),
column(4, selectInput(paste0("txt_", length(constraints$inputs) + 1), "Condition:", choices = c("<", ">"), selected = NULL)),
column(4, numericInput(paste0("val_", length(constraints$inputs) + 1), "Value:", value = NULL))
))
})
output$constraintInputs <- renderUI({
if (length(constraints$inputs) > 0){
lapply(constraints$inputs, function(x){
# fluidRow(column(width = 4, x[[1]]), column(width = 4, x[[2]]), column(width = 4, x[[3]]))
fluidRow(x[[1]], x[[2]], x[[3]])
#do.call(tagList, constraints$inputs)
})
}
})
s_plot <- eventReactive(input$run_button,{
ggpairs(data = data_input(), columns = c(input$s_cov))
})
output$s_plot <- renderPlot(s_plot())
}
shinyApp(ui = ui, server = server)
that generates a sidebar menu, where, if a user clicks on a plus sign, it generates three additional input elements that look like this:
I'm looking to fix two issues with the appearance:
- I would like to remove the "div col-sm-4" texts from the output.
- I would like the three input elements to appear in a single row with equal widths (and possibly with a minimum margin)
Any help would be greatly appreciated!
答案1
得分: 1
I don't have your CSV file so I can't test. I would try:
output$constraintInputs <- renderUI({
if(length(constraints$inputs) > 0) {
do.call(fluidRow, constraints$inputs)
}
})
英文:
I don't have your CSV file so I can't test. I would try:
output$constraintInputs <- renderUI({
if(length(constraints$inputs) > 0) {
do.call(fluidRow, constraints$inputs)
}
})
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论