我正在尝试从下拉列表中获取输入,并根据选择显示字符串
在ui.R:
selectInput(inputId = "engine",
label = h3("Select Search Engine"),
choices = c("Bing", "Google"),
selected = "Bing"))
<\ n>在server.R中:
if ( input$engine == "Bing"){
output$value <- renderText({ input$engine })
}
当if语句设置为像1 == 1这样的小事并且输出文本字符串时,这可以正常工作,但是当我尝试检查实际输入时(if语句没有触发)则不行。好像它应该是容易的东西,但我已经被困在这一段时间了......我做错了什么?
答案 0 :(得分:1)
我不知道你为什么要在这里使用if语句,但这有效:
library(shiny)
server <- function(input, output) {
output$value <- renderText({
if ( input$engine == "Bing") {
ret <- paste0("https://", input$text, "/?pid=", input$engine,"+{adgroupname}+{keyword}+{matchtype}+{adposition}")
} else {
ret <- paste0("https://", input$text, "/?pid=", input$engine,"+{adgroupname}+{keyword}+{matchtype}+{adposition}")
}
ret
})
}
ui <- shinyUI(fluidPage(
fluidRow(
column(3,
selectInput(inputId = "engine",
label = h3("Select Search Engine"),
choices = c("Bing", "Google"),
selected = "Bing")),
column(3,
textInput("text", label = h3("URL"), value = "www.test.com"))),
hr(),
h3("Final Url:"),
fluidRow(column(9, h4(textOutput("value"), style = "color:blue")))
))
shinyApp(ui = ui, server = server)