Created
July 29, 2016 18:38
-
-
Save aagarw30/3a0ef7d8ce8093d157c16e1799f5fb8d to your computer and use it in GitHub Desktop.
Tabsets and changing sidebarpanel widgets
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(shiny) | |
shinyServer(function(input,output)({ | |
## Get the value of the dataset that is selected by user from the list of datasets | |
data <- reactive({ | |
get(input$dataset) | |
}) | |
## to output the dataset | |
output$dat <- renderDataTable({ | |
data() | |
}) | |
# Pulling the list of variable for choice of variable x | |
output$varx <- renderUI({ | |
selectInput("variablex", "select the X variable", choices=names(data())) | |
}) | |
# Pulling the list of variable for choice of variable y | |
output$vary <- renderUI({ | |
selectInput("variabley", "select the Y variable", choices=names(data())) | |
}) | |
## Pulling the factor or categorical variables from the dataset | |
output$factor <- renderUI({ | |
t = split(names(data()),sapply(data(), function(x) paste(class(x), collapse=" "))) | |
selectInput("cat", "select the categorical variable", choices=t[[1]]) | |
}) | |
})) | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(shiny) | |
shinyUI(pageWithSidebar( | |
headerPanel("Conditional Panels"), | |
sidebarPanel( | |
selectInput("dataset", "select the desired dataset", choices=ls('package:datasets'), selected = "mtcars"), | |
conditionalPanel(condition="input.tabselected==1", | |
uiOutput("varx"), | |
uiOutput("vary") | |
), | |
conditionalPanel(condition="input.tabselected==2", | |
uiOutput("factor") | |
) | |
), | |
mainPanel( | |
tabsetPanel( | |
tabPanel("Data", value=0, dataTableOutput("dat")), | |
tabPanel("Plot", value=1), | |
tabPanel("Subset Data", value=2) | |
, id = "tabselected" | |
) | |
) | |
)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment