dag*_*g3r 2 r radio-button shiny
我是新的r闪亮,我试图将单选按钮的选定值作为变量,然后将其与其他东西连接.这是我的代码:
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
)
)
))
Run Code Online (Sandbox Code Playgroud)
server.R
library(shiny)
shinyServer(function(input, output) {
ncount <- reactive({input$rd})
print(ncount)
my_var <- paste(ncount,"100",sep="_")
})
Run Code Online (Sandbox Code Playgroud)
现在,当我打印时ncount,打印出"ncount"而不是存储在变量中的值.这里有什么我想念的吗?
谢谢
UI
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")
)
)
))
Run Code Online (Sandbox Code Playgroud)
服务器
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="_")
# })
})
Run Code Online (Sandbox Code Playgroud)