Black Lives Matter. Please consider donating to Black Girls Code today.
Learn how to use COVID-19 data in open source Dash apps. Register for the Sept 23rd webinar with IQT!

Can we have 2 Y axes lftin Plotly within Shiny with 2 different ranges for a geom_smooth gam model & geom_point?

We are trying to see if PLOTLY can allow a SECOND Y axis on the right to represent a different Y scale and attribute when I have 2 geoms (one geom_smooth with a gam and a second geom_point). In the below example, I am using two separate data frames for each geom and rendering this in Shiny using “renderPlotly”

output$vis <- renderPlotly({
p1 <- ggplot() + geom_point(
data = events(),
aes(
x = startlocal,
y = events.capacity,
text = paste(“Event Name”, nametext, “:”, “Duration:”, duration),
color = categories.name
),
size = 4
) + geom_smooth(
method = gam,
formula = y ~ s(x),
data = test2 ,
aes(x=DT_STAY_DATE, y= OCCUPANCY , color = PROPERTY_NAME)
)
gg <- ggplotly(p1)
gg

I know this can be done with ggplot but with some formatting and axis changes. Essentially I would like the Occupancy om the right and Capacity on the left and enable the user to see 2 different Y Axis scales and stil be able to zoom in/out per that scale. For example Capacity can be a range of 0-10000 whereas Occupancy can be 0-100.