【发布时间】:2019-02-01 20:01:58
【问题描述】:
我想将 input$var 中的变量存储到一个对象中,该对象可以与后面的字符串进行比较。目前,我只是尝试通过将其存储到对象 value_stored 来将其打印在屏幕上。但它没有打印任何东西*(错误:无法将类型“闭包”强制转换为“字符”类型的向量*)。这意味着它没有存储值。
library(shiny)
ui <- fluidPage(
titlePanel("censusVis"),
sidebarLayout(
sidebarPanel(
helpText("Create demographic maps with
information from the 2010 US Census."),
selectInput("var",
label = "Choose a variable to display",
choices = c("Percent White",
"Percent Black",
"Percent Hispanic",
"Percent Asian"),
selected = "Percent White")
),
mainPanel(
textOutput("selected_var")
textOutput("test")
)
)
)
server <- function(input, output) {
output$selected_var <- renderText({
paste(input$var)
})
value_store <- reactive(input$var)
output$test <- renderText({
paste(value_store)
})
# I want to use the value in input$var for some comparision.
# but value_store unable to store. Help.
}
shinyApp(ui = ui, server = server)
【问题讨论】:
标签: r shiny shiny-reactivity