Skip to content

Instantly share code, notes, and snippets.

@aagarw30
Last active January 9, 2020 14:03
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aagarw30/9281d07a454a16ea61a52a1215884291 to your computer and use it in GitHub Desktop.
Save aagarw30/9281d07a454a16ea61a52a1215884291 to your computer and use it in GitHub Desktop.
Gist to disable Plotly Tool Bar that appears on the right top corner of Plotly plot - R Shiny App code sample
## How to disable the plotly tool bar from right top corner
## We will be using the pressure dataset for sake of demo
## Single file shiny app
## install the packages if not already
## Load the required libraries
library(shiny) # for shiny functions
library(plotly) # for interactive plot and functions from R plotly
library(datasets)
## ui component starts here
ui <- fluidPage(
h3("R Plotly demo - disabling the Plotly tool bar"), ## heading
br(), ## just for line break/spacing
plotlyOutput("myplot") ## Plotly output object
)
## server component starts here
server <- function(input, output, session) {
## Render plotly section
output$myplot <- renderPlotly(
# plotly plot creation with required styling
plot_ly(data = pressure, x=~temperature, y=~pressure, type = "scatter",
mode=c("line", "points"), marker = list(color = "#737373", size = 10),
line = list(width = 2, color="red"),
hoverinfo = "text",
text = paste("Temperature ", pressure$temperature, "<br>", "Pressure ", pressure$pressure)
)
%>%
layout(title = "Pressure vs Temperature Plotly",
xaxis = list(title="Temperature", range=c(0,400), showgrid=F),
yaxis=list(title="Pressure", showgrid=F, titlefont=list(family="Arial", size=18, color="brown")),
annotations = list(xref = "Temperature", yref = "Pressure", x = 350, y = 100, align = "right",
text = "Temperature vs Pressure <br> Source : Pressure dataset ",
showarrow = F, ax = 0, ay = 0))
%>%
config(displayModeBar=FALSE) # to disable the plotly tool bar
)
}
## Shiny App Object
shinyApp(ui, server)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment