从闪亮创建文本列表/矢量

时间:2018-06-06 08:06:30

标签: r shiny

我们可以创建一个从闪亮的给出的矢量/输入列表吗?我想创建一个字符串向量,它存储从输入中获取的所有动作。

这是示例代码,因此只要我们更改输入,输出就会在同一行中发生变化。

require(shiny)

runApp(list(ui = pageWithSidebar(
  headerPanel("censusVis"),
  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"),
    sliderInput("range", 
                label = "Range of interest:",
                min = 0, max = 100, value = c(0, 100))
    ),
  mainPanel(htmlOutput("text")
  )
),
server = function(input, output) {
  output$text <- renderUI({
    str1 <- paste("You have selected", input$var)
  })
}
)
)

希望将动态输出视为(具体而言,它可以是n个输出......)

[1] You have selected Percent White
[2] You have selected Percent Asian
[3] You have selected Percent Black

1 个答案:

答案 0 :(得分:0)

这样的事情?

require(shiny)

runApp(list(ui = pageWithSidebar(
  headerPanel("censusVis"),
  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"),
    sliderInput("range", 
                label = "Range of interest:",
                min = 0, max = 100, value = c(0, 100))
  ),
  mainPanel(verbatimTextOutput("text")
  )
),
server = function(input, output) {
  val<-reactiveValues()
  val$txt<-""

  observeEvent(input$var,{
    new<-paste("You have selected", input$var)
    val$txt<-paste( val$txt,new,sep='\n')
  })
  output$text <- renderText({
    str1 <- val$txt
  })
}
)
)