gpt4 book ai didi

r shiny - 获取单选按钮值作为变量

转载 作者:行者123 更新时间:2023-12-04 09:23:47 24 4
gpt4 key购买 nike

我是 r shiny 的新手,我正在尝试将单选按钮的选定值作为变量,然后将其与其他内容连接起来。这是我的代码:

ui.R

library(shiny)
shinyUI(fluidPage(
titlePanel("This is test app"),

sidebarLayout(
sidebarPanel(
radioButtons("rd",
label="Select window size:",
choices=list("100","200","500","1000"),
selected="100")
),
mainPanel(
//Something
)
)
))

服务器.R

library(shiny)

shinyServer(function(input, output) {


ncount <- reactive({input$rd})
print(ncount)
my_var <- paste(ncount,"100",sep="_")

})

现在,当我打印 ncount 时,它会打印出“ncount”,而不是存储在变量中的值。我在这里遗漏了什么吗?

谢谢

最佳答案

用户界面

library(shiny)
shinyUI(fluidPage(
titlePanel("This is test app"),

sidebarLayout(
sidebarPanel(
radioButtons("rd",
label = "Select window size:",
choices = list("100" = 100,"200" = 200,"500" = 500,"1000" = 1000),
selected = 100)
),
mainPanel(
verbatimTextOutput("ncount_2")
)
)
))

服务器

library(shiny)

shinyServer(function(input, output) {


# The current application doesnt need reactive

output$ncount_2 <- renderPrint({
ncount <- input$rd
paste(ncount,"100",sep="_")
})

# However, if you need reactive for your actual data, comment the above part
# and use this instead


# ncount <- reactive({input$rd})
#
# output$ncount_2 <- renderPrint({
# paste(ncount(),"100",sep="_")
# })



})

关于r shiny - 获取单选按钮值作为变量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38618746/

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