Last active
May 10, 2017 21:24
-
-
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.
This file contains 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) | |
# 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 | |
}) | |
}) |
This file contains 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) | |
# 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") | |
) | |
) | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I was trying to implement the same but i get this error Error : object of type 'closure' is not subsettable all the time.