Sorry the app is private for now. The code is very complicated but here is the partial code that belongs to this plotly chart. The behavior is similar to my local machine. Req lines were originally put in my reactive and now I put them under renderplotly but still have the same issue. As you can see, I check for null input multiple times on top of req to prevent this issue but didn't work.
data_plot <- reactive ({
data[data$variable1==input$selection1, ] %>%
filter(selection2_NAME %in% input$selection2) %>%
select(column1, column2,column3,column4)
})
output$plot <- renderPlotly ({
req(input$selection1)
req(input$selection2)
req(input$selection3)
if (is.null(data_plot()))
{
return(NULL)
}
else if ((is.null(input$selection1)) | (is.null(input$selection2)) | (is.null(input$selection3))) {
return(NULL)
}
else if(input$selection1 == "A") {
plot_ly (x = data_plot()$column3,
y = ~ reorder(data_plot()$column1, data_plot()$column3),
type = 'bar') %>%
layout(title = '', titlefont = list(
family = "Myriad-Pro",
size = 16),
orientation = 'h',
xaxis = list(title = "",tickformat = "%",zeroline=FALSE,fixedrange=TRUE),
yaxis = list(title = "",fixedrange=TRUE),
margin = list(l = 220, pad=7)) %>%
add_annotations(xref = 'x', yref = 'y',
x =data_plot()$column3 ,
y = reorder(data_plot()$column1, data_plot()$column3),
text = paste0(round(data_plot()$column3*100, 0), '%'),
showarrow = FALSE,xanchor = 'left',xshift = 3,opacity = 0.7) %>%
config(displayModeBar = F)
}else if (input$selection1 == "B"){
plot_ly (x = data_plot()$column4 ,
y = ~ reorder(data_plot()$column1, data_plot()$column4),
type = 'bar',
color=~I(data_plot()$fillColor)) %>%
layout(title = '', titlefont = list(
family = "Myriad-Pro",
size = 16),
orientation = 'h',
xaxis = list(title = "",tickformat = "%",zeroline=FALSE,fixedrange=TRUE),
yaxis = list(title = "",fixedrange=TRUE),
margin = list(l = 220, pad=7)) %>%
add_annotations(xref = 'x', yref = 'y',
x =data_plot()$column4 ,
y = reorder(data_plot()$column1, data_plot()$column4 ),
text = paste0(round(data_plot()$column4 *100, 0), '%'),
showarrow = FALSE,xanchor = 'left',xshift = 3,opacity = 0.7) %>%
config(displayModeBar = F)
} else {
plot_ly (x = data_plot()$column2,
y = ~ reorder(data_plot()$column1, data_plot()$column2),
type = 'bar') %>%
layout(title = '', titlefont = list(
family = "Myriad-Pro",
size = 16),
orientation = 'h',
xaxis = list(title = "",tickformat = "%",zeroline=FALSE,fixedrange=TRUE),
yaxis = list(title = "",fixedrange=TRUE),
margin = list(l = 220, pad=7)) %>%
add_annotations(xref = 'x', yref = 'y',
x =data_plot()$column2,
y = reorder(data_plot()$column1, data_plot()$column2),
text = paste0(round(data_plot()$column2*100, 0), '%'),
showarrow = FALSE,xanchor = 'left',xshift = 3,opacity = 0.7) %>%
config(displayModeBar = F)
}
})