Anthony Pagan
December 2, 2018
URL
Library
install.packages(“plotly”) or
install the latest development version (on Github) via devtools:devtools::install_github(“ropensci/plotly”)
library(plotly)
library(ggplot2)
plot_ly(economics, x = ~pop)
#options(browser = 'FALSE')
t<-plot_ly(midwest, x = ~percollege, color = ~state,
type = "box",width = 800, height = 300)%>%
layout(margin = list(l = 100))
t
rangeslider(t)
p <- ggplot(txhousing, aes(date, median,
width = 800, height = 300)) +
geom_line(aes(group=city), alpha = 0.2)
p
#options(browser = 'FALSE')
subplot(
p, ggplotly(p, tooltip = "city",
width = 800, height = 300),
ggplot(txhousing, aes(date, median)) + geom_bin2d(),
ggplot(txhousing, aes(date, median)) + geom_hex(),
nrows =2, shareX= TRUE, shareY = TRUE,
titleY = FALSE, titleX = FALSE
)
library(plotly)
library(GGally)
pm<- ggpairs(iris)
ggplotly(pm,width = 800, height = 600)
Sys.setenv("plotly_username"="apag101")
Sys.setenv("plotly_api_key"="OyQslu5MKVQcEjx7aVJV")
api_create(t, filename = c("test"))
#Download from current account
api_download_plot("8","apag101")
#Download from https://plot.ly/~cpsievert/559/_1-vs-2/#/
api_download_plot("559", "cpsievert")
URL
Library
app.R has three components:
library(shiny)
# Define UI for application that draws a histogram
ui <- fluidPage(
# Application title
titlePanel("Old Faithful Geyser Data"),
# Sidebar with a slider input for number of bins
sidebarLayout(
sidebarPanel(
sliderInput("bins",
"Number of bins:",
min = 1,
max = 50,
value = 30)
),
# Show a plot of the generated distribution
mainPanel(
plotOutput("distPlot")
)
)
)
# Define server logic required to draw a histogram
server <- function(input, output) {
output$distPlot <- renderPlot({
# generate bins based on input$bins from ui.R
x <- faithful[, 2]
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')
})
}
# Run the application
shinyApp(ui = ui, server = server)
#install.packages('rsconnect')
rsconnect::setAccountInfo(name='apag101', token='98AFD680E6AB821CF1F430EF2A6DABFC', secret='rgMjLtYC8JcXgTFRb5TWOSzKlLXk4W4Nkp4fr1eU')
library(rsconnect)
rsconnect::deployApp('C:/Users/apagan/Documents/test2')
ui2 <- fluidPage(
plotlyOutput("plot"),
verbatimTextOutput("event")
)
server2 <- function(input, output) {
# renderPlotly() also understands ggplot2 objects!
output$plot <- renderPlotly({
plot_ly(mtcars, x = ~mpg, y = ~wt)
})
output$event <- renderPrint({
d <- event_data("plotly_hover")
if (is.null(d)) "Hover on a point!" else d
})
}
shinyApp(ui2, server2)