I’m making a Shiny page that have a plot and a table on the main panel that are created based on the options selected by the user on sidebarPanel.
In the ui I’m doing some reactive calculations based on the input choices selected by the user. The results of these calculations are used to create both the plot and the table. The table is appearing without a problem on Shiny, but on the plot space there is nothing. However, on the plot panel on RStudio the plot is appearing perfectly, it even changes correctly when I change the input selection on Shiny.
I made a much simple reproducible example, here it is:
sidebar <- dashboardSidebar(disable = TRUE)
body <- dashboardBody(fluidPage(
theme=shinytheme("cerulean"),
sidebarLayout(
sidebarPanel(
radioButtons("Fonte", "Selecione uma fonte", choices = c("Eólica", "Solar"), selected = "Eólica"),
selectInput("Ano", "Previsão até dezembro de qual ano", choices = c(2025:2030), selected = 2030),
radioButtons("Limite", "Selecione uma forma de determinar os limites inferior e superior",
choices = c("Tercis", "Nível de Confiança"), selected = "Tercis"),
conditionalPanel(
condition = "input.Limite == 'Nível de Confiança'",
sliderInput("Nivel", "Selecione intervalos de confiança(%)",
value = c(70,80), min = 50, max = 90, step = 5, ticks = FALSE)),
),
mainPanel(
plotOutput("Plot"),
DT::dataTableOutput("Tabela")
)
)))
ui <- dashboardPage(header, sidebar, body)
server <- function(input, output) {
Serie <- reactive({
if (input$Fonte == "Solar") {
Serie <- list(data.frame(A = c(1:7), Year = c(2010:2016)),data.frame(A = c(4:10), Year = c(2010:2016)),data.frame(A = c(11:17), Year = c(2010:2016)))
} else {
Serie <- list(data.frame(A = c(20:26), Year = c(2010:2016)),data.frame(A = rep(11,7), Year = c(2010:2016)),data.frame(A = rep(10,7), Year = c(2010:2016)))
}
return(Serie)
})
output$Plot <- renderPlotly({
plot(Serie()[[2]]$Year, Serie()[[2]]$A , col = "darkblue", type ='l',lty = 1, ylim= c(1,30), xlim = c(2010,2016))
lines(Serie()[[1]]$Year, Serie()[[1]]$A , col='darkred', lty = 1)
lines(Serie()[[3]]$Year, Serie()[[3]]$A, col='darkred', lty = 1)
grid()
legend(2021,3000,legend = c("Projeção central","1º e 3º tercis"),
col = c("darkblue", "darkred"), cex = 1, lty = 1)
})
output$Tabela <- DT::renderDataTable({
Serie()[[2]]
})
}
shinyApp(ui, server)
I dont know if this is the answer, but I tried to create an action button and a make the plot a eventReactive, but it also didnt work. I also tried to use plot instead of plotly, but had the same problem.
Felipe Gonçalves is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.