I have a piece of code where i need to display different tables depending on the userinput of the SelectInput command in R. I simply want to display table base_level2 when the userinput is Level 2 and display base_level3 when the user selects with selectInput Level 3 I am not sure if reactive command helps me with this but at the time i am really confused what should I do. Thanks everyone beforehand.
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)
Added some fake data to make it work, fixed the syntax error identified by HubertL in the comments, and it worked fine:
Yielding: