I am trying to include a interactive chunk in a HTML Markdown document, with the following code, if I select and run the UI,server and ShinyApp sections I get the desire result, but if I render-knit the full code I get a freeze image and I can't chose among the options, how can I get a reactive version in the HTML document?
title: "Untitled"
author: "Martin"
date: "29/12/2020"
output: html_document
knitr::opts_chunk$set(echo = TRUE)
library(htmltools)
library(tidyverse)
library(shiny)
PuntoB<-c(1,3,6,10)
BN<-data.frame(Fecha=seq(1,10),Plazo3=rnorm(10,7.8,2),Plazo5=rnorm(10,7.8,2),Plazo7=rnorm(10,7.8,2),Plazo10=rnorm(10,7.8,2),Plazo20=rnorm(10,7.8,2),Plazo30=rnorm(10,7.8,2))
ui <-fluidPage(
fluidRow(
(checkboxGroupInput("Plazos",
h3("Plazos BONOS "),
choices=list("Plazo 3"=1,
"Plazo 5"=2,
"Plazo 10"=3,
"Plazo 20"=4,
"Plazo 30"=5),
selected=1))
),
plotOutput(outputId = "Plazo")
)
server<-function(input,output){
Color=character()
Leyenda=character()
output$Plazo <-renderPlot({
plot(rep(5,length(BN$Plazo3)),type="l",col="red",xaxt="none",ylab="Tasa",xlab="Fecha",main="Historico Bondes",ylim=c(0,20))
axis(1, at=PuntoB,labels=BN$Fecha[PuntoB])
if(1 %in% input$Plazos) {lines(BN$Plazo3,type="l",col="magenta",pch=19,cex=.8)
Color<-"magenta"
Leyenda<-"Plazo 3"}
if(2 %in% input$Plazos) {lines(BN$Plazo5,type="l",col="blue",pch=19,cex=.8)
Color<-c(Color,"blue")
Leyenda<-c(Leyenda,"Plazo 5")}
if(3 %in% input$Plazos) {lines(BN$Plazo10,type="l",col="green",pch=19,cex=.8)
Color<-c(Color,"green")
Leyenda<-c(Leyenda,"Plazo 10")}
if(4 %in% input$Plazos) {lines(BN$Plazo20,type="l",col="orange",pch=19,cex=.9)
Color<-c(Color,"orange")
Leyenda<-c(Leyenda,"Plazo 20")}
if(5 %in% input$Plazos) {lines(BN$Plazo30,type="l",col="purple",pch=19,cex=.9)
Color<-c(Color,"purple")
Leyenda<-c(Leyenda,"Plazo 30")}
# abline(h=5,col="red")
legend("topright", legend=Leyenda,
col=Color, lty=1,cex=1)
})
}
shinyApp(ui=ui,server=server)