selectInput不起作用

时间:2017-01-03 07:47:47

标签: r shiny

library(shiny)

shinyUI(fluidPage(

  # Application title
  titlePanel(h1("TEST", align = "center", style = "color:red")),
  tabsetPanel(
    tabPanel("Marketing",sidebarLayout(
      sidebarPanel(textInput("id",label = "Enter consultant Name"),
                   selectInput('s1','Select Names',choices = c('i','ij','ishu','ishan'),selected = NULL),
                   actionButton("a","Submit")
                  ),
      mainPanel(
        textOutput('out'),
        textOutput("sout")
      )
     )
    ),

    tabPanel("Recruitment",sidebarLayout(
      sidebarPanel(textInput("id1",label = "Enter consultant Name"),
                   actionButton("a1","Submit")
                  ),
      mainPanel(
        textOutput('out1')
      )
     )
    ),

    tabPanel("Engineering",sidebarLayout(
      sidebarPanel(textInput("id2",label = "Enter consultant Name"),
                   actionButton("a2","Submit")
                  ),
      mainPanel(
        textOutput('out2')
      )
     )
    ),

    tabPanel("Finance",sidebarLayout(
      sidebarPanel(textInput("id3",label = "Enter consultant Name"),
                   actionButton("a3","Submit")
                  ),
      mainPanel(
        textOutput('out3')
      )
     )
    ),

    tabPanel("Legal",sidebarLayout(
      sidebarPanel(textInput("id4",label = "Enter consultant Name"),
                   actionButton("a4","Submit")
                  ),
      mainPanel(
        textOutput('out4')
      )
     )
    ),

    tabPanel("Test",
        mainPanel(
        tableOutput('table')
      )       
     )  
  )
)
)

库(有光泽)

 shinyServer(function(input, output) {
      observeEvent(input$a,
      output$out <- renderText(
                    input$id),
       output$sout <- renderText(input$s1)
     )

      observeEvent(input$a1,
                   output$out1 <- renderText(

                     input$id1
                   )
      )

      observeEvent(input$a2,
                   output$out2 <- renderText(

                     input$id2
                   )
      )

      observeEvent(input$a3,
                   output$out3 <- renderText(
                     input$id3
                   )
      )

      observeEvent(input$a4,
                   output$out4 <- renderText(
                     input$id4
                   )
      )
      output$table <- renderTable(read.csv('csv1.csv'))
    })

在这个应用程序中,每当用户点击id为“a”的动作按钮时,我都会尝试从selectInput函数中获取名称。我试图在observeEvent()函数下执行此操作,但得到错误: - “eval中的错误:'封闭'类型的无效'envir'参数”。请帮忙 提前谢谢

1 个答案:

答案 0 :(得分:3)

您的服务器功能似乎存在问题。您需要在observeEvent内的{}中包含多行代码。只需替换您的代码:

observeEvent(input$a,
      output$out <- renderText(
                    input$id),
       output$sout <- renderText(input$s1)
     )

以下内容:

observeEvent(input$a,{
    output$out <- renderText(input$id)
    output$sout <- renderText(input$s1) 
  })

我认为这可以解决问题。

希望它有所帮助!