1

我有一段代码,我需要根据 R 中 SelectInput 命令的用户输入显示不同的表。我只想在用户输入为 2 级时显示表 base_level2 并在用户使用 selectInput 3 级选择时显示 base_level3 我是不确定反应式命令是否对我有帮助,但当时我真的很困惑我该怎么做。提前谢谢大家。

用户界面

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


      )


 )

服务器.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)
4

1 回答 1

0

添加了一些虚假数据以使其正常工作,修复了 HubertL 在评论中识别的语法错误,并且工作正常:

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 )

产量: 在此处输入图像描述

于 2016-12-30T21:39:24.407 回答