Challenge writing HTML UI with a plotlyOutput

I've been trying to write an RShiny UI in HTML, and am unable to add an interactive plolty graph to my app. I generate the plotly graph as shown:

#shiny app
library(shiny)
library(ggplot2)
library(plotly)
df <- data.frame(x = c(1,2,3),
                 y = c(4,5,6))

server <- function(input,output){
  output$fig <- renderPlotly({
    fig <- ggplot(df, aes(x = x, y = y)) +
      geom_line(color = "green") +
      theme_bw()
    return(ggplotly(fig))
  })
}

shinyApp(ui = htmlTemplate("www/index.html") , server)

and then calling the id in my index.HTML like this:

<html>
    <head>
        <script src="shared/jquery.js" type="text/javascript"></script>
        <script src="shared/shiny.js" type="text/javascript"></script>
        <link rel="stylesheet" type="text/css" href="shared/shiny.css"/>
      </head>
<body>
    <h3>header</h3>
    <div id = "fig" class = "shiny-plot-output" style = "width: 100%; height: 400px;"></div>
</body>
</html>

But my plot does not appear on the app. Any tips? I know the plotlyOutput is rendered as a combo of HTML js and CSS but am unsure how I would call this "class" in HTML or how to embed this in a page

I'm not offering a guaranteed solution, but I do see a mistake that will keep you from your goal.
the HTML you have for fig is as if it were a plotOutput and not a plotlyOutput, which would be:

<div id="fig" style="width:100%; height:400px; " class="plotly html-widget html-widget-output shiny-report-size"></div>

This topic was automatically closed 54 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.