Generating UI elements
shinyUI(navbarPage('Electoral College',
# Create a tab panel for your map
tabPanel('Map',
titlePanel('Electoral College Votes'),
# Create sidebar layout
sidebarLayout(
# Side panel for controls
sidebarPanel(
# Input to select variable to map
selectInput('mapvar', label = 'Variable to Map',
choices = list("Population" = 'population',
'Electoral Votes' = 'votes'))),
# Main panel: display plotly map
mainPanel(plotlyOutput('map')
)
)
),
# Create a tabPanel to show your scatter plot
tabPanel('Scatter',
# Add a titlePanel to your tab
titlePanel('Population v.s. Vote Power'),
# Create a sidebar layout for this tab (page)
sidebarLayout(
# Create a sidebarPanel for your controls
sidebarPanel(
# Make a textInput widget for searching for a state in your plot
textInput('search', label="Find a State", value = '')),
# Create a main panel, in which you should display your plot
mainPanel(plotlyOutput('scatter')
)
)
)
))
output$map <- renderPlotly({
return(BuildMap(joined.data, input$mapvar))
output$distPlot <- renderPlot({
x <- faithful[, 2] # Old Faithful Geyser data
bins <- seq(min(x), max(x), length.out = input$bins + 1)
# draw the histogram with the specified number of bins
hist(x, breaks = bins, col = 'darkgray', border = 'white')
})
output$userText <- renderText({
return(paste0('The user typed: ', input$text))
})
output$histogram <- renderPlot({
x <- rnorm(1000)
return(hist(x, col = input$color))
})
selectInput('mapvar', label = 'Variable to Map', choices = list("Population" =
'population', 'Electoral Votes' = 'votes')),
plotlyOutput('map')
plotOutput("distPlot")
textInput("text", label = h3("Text input"), value = "Enter text..."),
textOutput('userText')
radioButtons("color", label = "Color",
choices = list("Green" = 'green', "Blue" = 'blue'),
selected = 'green'),
plotOutput('histogram')
// take a string and convert to variable name
x <- 42
eval(parse(text = "x"))
[1] 42
// other way around
x <- 42
deparse(substitute(x))
[1] "x"