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