Skip to content

Instantly share code, notes, and snippets.

@trestletech
Last active May 10, 2017 21:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save trestletech/8522949 to your computer and use it in GitHub Desktop.
Save trestletech/8522949 to your computer and use it in GitHub Desktop.
Shiny example with a custom layout that filters the 'mpg' dataset from the 'ggplot2' library and displays the output in a table.
library(shiny)
# Load the ggplot2 package which provides
# the 'mpg' dataset.
library(ggplot2)
# Define a server for the Shiny app
shinyServer(function(input, output) {
# Filter data based on selections
output$table <- renderTable({
data <- mpg
if (input$man != "All"){
data <- data[data$manufacturer == input$man,]
}
if (input$cyl != "All"){
data <- data[data$cyl == input$cyl,]
}
if (input$trans != "All"){
data <- data[data$trans == input$trans,]
}
data
})
})
library(shiny)
# Load the ggplot2 package which provides
# the 'mpg' dataset.
library(ggplot2)
# Define the overall UI
shinyUI(
fluidPage(
titlePanel("MPG Filter"),
# Create a new Row in the UI for selectInputs
fluidRow(
div(class="span4",
selectInput("man",
"Manufacturer:",
c("All",
unique(as.character(mpg$manufacturer))))
),
div(class="span4",
selectInput("trans",
"Transmission:",
c("All",
unique(as.character(mpg$trans))))
),
div(class="span4",
selectInput("cyl",
"Cylinders:",
c("All",
unique(as.character(mpg$cyl))))
)
),
# Create a new row for the table.
fluidRow(
tableOutput(outputId="table")
)
)
)
@PraoYoda
Copy link

I was trying to implement the same but i get this error Error : object of type 'closure' is not subsettable all the time.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment