Generate list to update main plot in plotlyProxy
lg_profile_update_main.Rd
This function generates a list to update the main axe in existing plotly graph with plotlyProxy.
Arguments
- data
A data frame containing the data to be plotted.
- y
The name of the y-axis variable to plot.
- y_label
The label for the y-axis.
- y_label_category
The category label for the y-axis.
Examples
if (FALSE) {
data <- data.frame(
measure = 1:10,
selected_metric = rnorm(10, mean = 1)
)
output$scatter_plot <- renderPlotly({
plot_ly(data, x = ~measure, y = ~selected_metric, type = 'scatter', mode = 'line')
})
data_updated <- data.frame(
measure = 1:10,
selected_metric = rnorm(10, mean = 1)
)
selected_metric_name <- "my metric"
select_metric_category <- "my metric category"
update_main_axe <-
lg_profile_update_main(
data = data_updated,
y = data_updated[[selected_metric]],
y_label = selected_metric_name,
y_label_category = r_val$select_metric_category
)
plotlyProxy("scatter_plot") %>%
plotlyProxyInvoke("deleteTraces", 0) %>%
plotlyProxyInvoke("addTraces", update_main_axe$trace, 0) %>%
plotlyProxyInvoke("relayout", update_main_axe$layout)
}