2017-01-03 52 views
0
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') 
    )  
    ) 
) 
) 
) 

庫(閃亮)selectInput不工作

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')) 
    }) 

在這個程序,我想從selectInput功能,只要與ID 「A」 actionbutton用戶點擊名稱。我試圖在observeEvent()函數下執行此操作,但得到錯誤: - 「eval:invalid'envir'參數的類型爲'closure'」。請幫助 在此先感謝

回答

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) 
    }) 

我認爲這將解決這個問題。

希望它有幫助!

+0

它的工作,非常感謝。 –