2016-12-30 2 views
1

Ich habe ein Stück Code, wo ich verschiedene Tabellen abhängig von der Benutzereingabe des Befehls SelectInput in R anzeigen müssen. Ich möchte einfach Tabelle base_level2 anzeigen, wenn der Benutzereingang Ebene 2 ist und display base_level3, wenn der Benutzer wählt mit SelectInput Level 3 Ich bin mir nicht sicher, ob reaktive Befehl mir dabei hilft, aber zu der Zeit bin ich wirklich verwirrt, was ich tun soll. Danke allen im Voraus.Wie ändere ich die angezeigte Tabelle in Abhängigkeit von dem userInput

ui.R

library(shiny) library(radarchart) library(fmsb) 
# Define UI for random distribution application 

shinyUI(pageWithSidebar( headerPanel('A competency profiling model 
    for Software engineers'), sidebarPanel(

selectInput("dataset", "Choose Level of competence :", 
      choices = c("Level 2", "Level 3"), selected = "Level 2"), 

radioButtons("selectedCategory","Make your choice of Skills : ", rownames(x), selected = "Professional skills"), 
checkboxGroupInput('selectedLevels', 'Who to include', 
        names(scores[]), selected="Technical Junior"), 
sliderInput("Candidate", "Candidate number:", 
      min = 1, max = 50, value = 1)), 
mainPanel(
    tabsetPanel(type="tabs", 
      tabPanel('Level2/Level3 RCD frame', tableOutput("table")), 
      tabPanel("Candidates ACD frame ", tableOutput("candidate")), 
      tabPanel("Radar Plot #1", chartJSRadarOutput("radar", width = "450", height = "300"), width = 7), 
      tabPanel("Radar Plot #2" ,plotOutput("triangle", width = "100%", height = "900px"), width = 7), 
      tabPanel("Clustering Plots",plotOutput("cluster", width = "100%", height = "900px"), width = 7), 
      tabPanel("Correlation Plots",plotOutput("corellation",width = 

"100%", height = 
"900px"),width = 7), 
       tabPanel("Classification Tree", plotOutput("class",width = "100%", height = "900px"),width = 7)) 
      ) 


    ) 


) 

server.R

function(input, output) { 


    datasetInput <- reactive({ 
    switch(input$dataset, 
      "Level 2" = as.matrix(base_level2), 
      "Level 3" = as.matrix(base_level3) 
      ) 
    }) 

    output$table <- renderTable({(datasetInput)},rownames=TRUE,striped = TRUE,hover = TRUE, bordered = TRUE) 
+0

Da 'datasetInput' ein reaktives ist, müssen Sie es auf diese Weise verwenden' datasetInput() ' – HubertL

+0

Irgendwelche Bewertungen für mich? –

Antwort

0

Added einige gefälschte Daten, um es fest zu machen arbeiten, die Syntaxfehler durch HubertL in den Kommentaren identifiziert, und es funktionierte gut:

library(shiny) 
library(radarchart) 
library(fmsb) 

# Fake Data 
x <- data.frame(skilz = c("Professional Skills","Technical Skills","Soft Skills"),a = c(1,2,3),b = c(11,12,13),row.names = "skilz") 
scores <- c("Technical Junior" = 1,"Technical Senior" = 2) 
base_level2 <- data.frame(x = c(1,2,3),y = c(4,5,6),z = c(7,8,9)) 
base_level3 <- data.frame(x = c(11,12,13),y = c(14,15,16),z = c(17,18,19)) 

# Define UI for random distribution application 

u <- shinyUI(pageWithSidebar(headerPanel('A competency profiling model for Software engineers'), 
    sidebarPanel(
     selectInput("dataset","Choose Level of competence :", 
        choices = c("Level 2","Level 3"),selected = "Level 2"), 

     radioButtons("selectedCategory","Make your choice of Skills : ",rownames(x),selected = "Professional skills"), 
     checkboxGroupInput('selectedLevels','Who to include', 
          names(scores[]),selected = "Technical Junior"), 
     sliderInput("Candidate","Candidate number:", 
        min = 1,max = 50,value = 1)), 
    mainPanel(
     tabsetPanel(type = "tabs", 
        tabPanel('Level2/Level3 RCD frame',tableOutput("table")), 
        tabPanel("Candidates ACD frame ",tableOutput("candidate")), 
        tabPanel("Radar Plot #1",chartJSRadarOutput("radar",width = "450",height = "300"),width = 7), 
        tabPanel("Radar Plot #2",plotOutput("triangle",width = "100%",height = "900px"),width = 7), 
        tabPanel("Clustering Plots",plotOutput("cluster",width = "100%",height = "900px"),width = 7), 
        tabPanel("Correlation Plots",plotOutput("corellation",width = "100%",height = 
     "900px"),width = 7),tabPanel("Classification Tree",plotOutput("class",width = "100%",height = "900px"),width = 7))) 
) 
) 

s <- 
function(input,output) { 


    datasetInput <- reactive({ 
    switch(input$dataset, 
     "Level 2" = as.matrix(base_level2), 
     "Level 3" = as.matrix(base_level3) 
     ) 
    }) 

    output$table <- renderTable({(datasetInput()) }, 
       rownames = TRUE,striped = TRUE,hover = TRUE,bordered = TRUE) 
} 

shinyApp(ui=u,server=s) 

Nachgeben: enter image description here

+0

vielen dank für die antwort! –

Verwandte Themen