if(is.factor(df_{{ env_id }}[["{{ meta_column }}"]])){ if("{{ meta_column }}" %in% names(colormaps)) colors_{{ env_id }} <- colormaps[["{{ meta_column }}"]] else colors_{{ env_id }} <- "Set1" bars_{{ meta_column }} <- plotly::plot_ly(sd_{{ env_id }}, colors = colors_{{ env_id }}, x = df_{{ env_id }}[["{{ meta_column }}"]], color = df_{{ env_id }}[["{{ meta_column }}"]]) %>% plotly::layout( xaxis = list(title = names(df_{{ env_id }}["{{ meta_column }}"])), yaxis = list(title = "Number of observations"), barmode = "overlay", showlegend = FALSE ) %>% plotly::highlight("plotly_selected") bars_{{ meta_column }} } else { if(grouping_{{ env_id }} %in% names(colormaps)) colors_{{ env_id }} <- colormaps[[grouping_{{ env_id }}]] else colors_{{ env_id }} <- "Set1" box_{{ meta_column }} <- plotly::plot_ly(sd_{{ env_id }}, colors = colors_{{ env_id }}, x = df_{{ env_id }}[[grouping_{{ env_id }}]], y = df_{{ env_id }}[["{{ meta_column }}"]], color = df_{{ env_id }}[[grouping_{{ env_id }}]]) %>% plotly::add_boxplot() %>% plotly::layout( xaxis = list(title = grouping_{{ env_id }}), yaxis = list(title = names(df_{{ env_id }}["{{ meta_column }}"])), showlegend = FALSE ) %>% plotly::highlight("plotly_selected") box_{{ meta_column }} }
# # Output # output$plot_box_bar_{{ meta_column }}_{{ env_id }} <- plotly::renderPlotly({ if(is.factor(df_{{ env_id }}()$df[["{{ meta_column }}"]])){ if("{{ meta_column }}" %in% names(colormaps)) colors <- colormaps[["{{ meta_column }}"]] else colors <- "Set1" bars <- plotly::plot_ly(df_{{ env_id }}()$sd, colors = colors, x = df_{{ env_id }}()$df[["{{ meta_column }}"]], color = df_{{ env_id }}()$df[["{{ meta_column }}"]]) %>% plotly::layout( xaxis = list(title = names(df_{{ env_id }}()$df["{{ meta_column }}"])), yaxis = list(title = "Number of observations"), barmode = "overlay", showlegend = FALSE ) %>% plotly::highlight("plotly_selected") bars } else { if(df_{{ env_id }}()$grouping %in% names(colormaps)) colors <- colormaps[[df_{{ env_id }}()$grouping]] else colors <- "Set1" box <- plotly::plot_ly(df_{{ env_id }}()$sd, colors = colors, x = df_{{ env_id }}()$df[[df_{{ env_id }}()$grouping]], y = df_{{ env_id }}()$df[["{{ meta_column }}"]], color = df_{{ env_id }}()$df[[df_{{ env_id }}()$grouping]]) %>% plotly::add_boxplot() %>% plotly::layout( xaxis = list(title = df_{{ env_id }}()$grouping), yaxis = list(title = names(df_{{ env_id }}()$df["{{ meta_column }}"])), showlegend = FALSE ) %>% plotly::highlight("plotly_selected") box } }) # # Layout of component # renderUI({plotly::plotlyOutput("plot_box_bar_{{ meta_column }}_{{ env_id }}", height = "100%")})
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.