【发布时间】:2020-08-12 16:29:32
【问题描述】:
我想根据用户输入生成一个字符串列表。但是当我使用粘贴功能时,我收到了这个错误:
object 'b' not found
我正在寻找一种方法来返回所有要在服务器中显示或进一步使用的输入值 --
例如:
LV =~ x1 + x2 + x3
LV ~ LV1
等等。
也许我需要将用户输入的值存储为反应值。但我不确定该怎么做。
这是完整的代码:
library(shiny)
newlist <- as.list(c("LV", "LV2", "x1", "x2", "x3", "x4", "x5", "x6"))
lvar <- function(...) {
params <- list(...)
stopifnot(length(params)%%2==0)
lefts = params[seq(1,length(params), by=2)]
rights = params[seq(2,length(params), by=2)]
rights <- Map(paste, rights, collapse="+")
paste(paste0(lefts, " =~", rights), collapse="\n")
}
regs <- function(...) {
params <- list(...)
stopifnot(length(params)%%2==0)
lefts = params[seq(1,length(params), by=2)]
rights = params[seq(2,length(params), by=2)]
rights <- Map(paste, rights, collapse="+")
paste(paste0(lefts, "~", rights), collapse="\n")
}
ui <- fluidPage(
sidebarLayout(
sidebarPanel(
selectInput("variable1", "Variable:", choices = c(' ', newlist), selected = NULL),
selectInput("variable2", "Variable:", choices = c(' ', newlist), selected = NULL, multiple = TRUE),
selectInput("variable3", "Variable:", choices = c(' ', newlist), selected = NULL),
selectInput("variable4", "Variable:", choices = c(' ', newlist), selected = NULL, multiple = TRUE)
),
mainPanel(
verbatimTextOutput("listout1"),
verbatimTextOutput("listout2"),
verbatimTextOutput("listout3"),
verbatimTextOutput("listout4"),
verbatimTextOutput("listout5")
)
)
)
server <- function(input, output) {
output$listout1 <- renderText({
input$variable1
})
output$listout2 <- renderText({
input$variable2
})
output$listout3 <- renderText({
a <- lvar(lefts = input$variable1, rights = input$variable2)
})
output$listout4 <- renderText({
b <- regs(lefts = input$variable3, rights = input$variable4)
})
output$listout5 <- renderText({
paste(a, b, sep = "/n")
})
}
shinyApp(ui = ui, server = server)
【问题讨论】:
标签: r shiny concatenation