Loading Plotly Diagrams Through Rmarkdown?

I wrote a loop that made 10 graphs in R:

library(plotly)

for (i in 1:10)

{

d_i = data.frame(x = rnorm(100,100,100), y = rnorm(100,100,100))

title_i = paste0("title_",i)

p_i = plot_ly(data = d_i, x = ~x, y = ~y) %>% layout(title = title_i)

htmlwidgets::saveWidget(as_widget(p_i), paste0("plot_",i, ".html"))

}

I would like to adapt this code so that the drop down menu allows the user to load the graph that is being searched for. For example, if the user searches for "plot_7", then plot_7 is displayed.

I tried the following code:

---
title: "Test Dashboard"
output: 
  flexdashboard::flex_dashboard:
    orientation: rows
    vertical_layout: fill
runtime: shiny
---

```{r setup, include=FALSE}
library(flexdashboard)
library(shiny)

Column {data-width=100}

Window 1

plots = rep("plot", 10)
i = seq(1:100)
choice = paste0(plots, "_",i)
selectInput("project", label = NULL, choices = choice)

Column {data-width=400}

Chart B

renderPlot({
<object class="one" type="text/html" data="plot_i.html"></object>
})

But this returns the following error:

Error: <text<:2:1 unexpected '<' 
1: renderPlot({
2:<
 ^

Can someone please show me how I can fix this?

Thank you!

This topic was automatically closed 42 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.