-
-
Save mbannert/4214584 to your computer and use it in GitHub Desktop.
Shiny example: dynamic input fields
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
# Some pre-computed stuff in R. In this example, just assign values to a var | |
data_sets <- c("mtcars", "morley", "rock") | |
shinyServer(function(input, output) { | |
# Drop-down selection box for which data set | |
output$choose_dataset <- reactiveUI(function() { | |
selectInput("dataset", "Data set", as.list(data_sets)) | |
}) | |
# Check boxes | |
output$choose_columns <- reactiveUI(function() { | |
# Get the data set with the appropriate name | |
dat <- get(input$dataset) | |
colnames <- names(dat) | |
# Create the checkboxes and select them all by default | |
checkboxGroupInput("columns", "Choose columns", | |
choices = colnames, | |
selected = colnames) | |
}) | |
# Output the data | |
output$data_table <- reactiveTable(function() { | |
# Get the data set | |
dat <- get(input$dataset) | |
# Keep the selected columns | |
dat <- dat[, input$columns, drop = FALSE] | |
# Return first 20 rows | |
head(dat, 20) | |
}) | |
}) |
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
# Define UI for miles per gallon application | |
shinyUI(pageWithSidebar( | |
headerPanel(""), | |
sidebarPanel( | |
uiOutput("choose_dataset"), | |
uiOutput("choose_columns") | |
), | |
mainPanel( | |
tableOutput("data_table") | |
) | |
)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi,
I am new to 'R' , I have gone through the above example. I have a requirement similar to this example.
I am confused from where did you take the data for the above example. can please give some idea for the above example.