gpt4 book ai didi

R Shiny Conditional Input 标签基于另一个输入

转载 作者:行者123 更新时间:2023-12-04 17:55:46 26 4
gpt4 key购买 nike

我试图让 conditionalPanellabel 包含从输出派生的名称,该输出是使用另一个输入创建的。我一直在研究,但还没有弄清楚如何做到这一点。以下是我尝试过的方法,但无济于事。

ui.R

shinyUI(
fluidPage(
titlePanel("example"),
sidebarLayout(
sidebarPanel(

numericInput("criteria_count",
label = "How many criteria are being considered? (max = 5)",
2, min = 2, max = 5),

textInput("critera_text",
label = "Type the different criteria titles, seperated by commas.",
value = "Example A, Example B"),
#verbatimTextOutput("value"),

conditionalPanel(condition = "input.criteria_count == 2",
selectInput("main_cri1",
label = paste0("How much more important is ", output.criteria1, " than ", output.criteria2, "?"),
c("9 (Extremely more important)",
"7 (Much more important)",
"5 (Moderately more important)",
"3 (Slightly more important)",
"1 (Equally as important)",
"1/3 (Slightly less important)",
"1/5 (Moderately less important)",
"1/7 (Much less important)",
"1/9 (Extremely less important)")))

)
)
)
)

server.R

library(shiny)

shinyServer(function(input, output){

output$criteria1 <- renderText({
strsplit(input$critera_text, ", ")[[1]][1]
})

output$criteria2 <- renderText({
strsplit(input$critera_text, ", ")[[1]][2]
})

})

鉴于上面的 ui.R,conditionalPanellabel 应如下所示:

“示例 A 比示例 B 重要多少?”

最佳答案

试试这个(app.R)

ui <-
fluidPage(titlePanel("example"),
sidebarLayout(

sidebarPanel(
numericInput(
"criteria_count",
label = "How many criteria are being considered? (max = 5)",
2,
min = 2,
max = 5
),

textInput("critera_text",
label = "Type the different criteria titles, seperated by commas.",
value = "Example A, Example B"),

conditionalPanel(condition = "input.criteria_count == 2",
uiOutput("mySelectInput"))
),

mainPanel()

))

server <-
function(input, output) {
output$mySelectInput <- renderUI({
criteria1 <- strsplit(input$critera_text, ", ")[[1]][1]
criteria2 <- strsplit(input$critera_text, ", ")[[1]][2]

selectInput(
"main_cri1",
label = paste0(
"How much more important is ",
criteria1,
" than ",
criteria2,
"?"
),
choices = c(
"9 (Extremely more important)",
"7 (Much more important)",
"5 (Moderately more important)",
"3 (Slightly more important)",
"1 (Equally as important)",
"1/3 (Slightly less important)",
"1/5 (Moderately less important)",
"1/7 (Much less important)",
"1/9 (Extremely less important)"
)
)
})
}

shinyApp(ui = ui, server = server)

关于R Shiny Conditional Input 标签基于另一个输入,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40616819/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com