如何根据用户输入更改显示表输入
问题描述:
我有一段代码,我需要显示不同的表,具体取决于R中SelectInput命令的userinput。 我只想在userinput为Level 2时显示表base_level2并显示base_level3当用户选择selectInput级别3 我不确定被动命令是否帮助我,但在那个时候我真的很困惑我该怎么做。 预先感谢大家。如何根据用户输入更改显示表输入
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)
答
增加了一些假的数据,使其工作,通过固定在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)
+0
非常感谢您的回答! –
由于'datasetInput'是一个反应,你必须以这种方式使用'datasetInput()' – HubertL
对我而言的任何反馈? –