When running the below "MWE code using renderUI", in R studio console I get the message "Error in :: argument of length 0" though the App keeps working correctly. This MWE reflects a simple adaptation from the below "MWE code this was adapted from without renderUI" where renderUI isn't used, and this MWE doesn't show any type of error.
What could be causing this error? I need renderUI
.
MWE code using renderUI:
library(shiny)
library(tidyverse)
library(ggplot2)
ui <- fluidPage(
sidebarLayout(sidebarPanel(uiOutput("panel")),
mainPanel(plotOutput("plot")),
))
server <- function(input, output, session) {
output$panel <- renderUI({
tagList(
sliderInput('samples','Number of samples (X):',min=2,max=10,value=10),
actionButton("add", "Add scenario")
)
})
numScenarios <- reactiveValues(numS=1)
observeEvent(input$add, {showModal(modalDialog(footer = modalButton("Close")))
numScenarios$numS <- (numScenarios$numS+1)
})
output$plot <- renderPlot({
v <- tibble()
for (i in 1: numScenarios$numS){
results=tibble(Scenario=i,X=1:input$samples,Y=runif(input$samples))
v <- bind_rows(v, results)
}
v %>% ggplot() + geom_line(aes(x=X, y=Y, colour=as.factor(Scenario)))
})
}
shinyApp(ui, server)
MWE code this was adapted from without renderUI:
ui <- fluidPage(
sliderInput('samples','Number of samples (X):',min=2,max=10,value=10),
actionButton("add", "Add scenario"),
plotOutput("plot"),
)
server <- function(input, output, session) {
numScenarios <- reactiveValues(numS=1)
observeEvent(input$add, {showModal(modalDialog(footer = modalButton("Close")))
numScenarios$numS <- (numScenarios$numS+1)
})
output$plot <- renderPlot({
v <- tibble()
for (i in 1: numScenarios$numS){
results=tibble(Scenario=i,X=1:input$samples,Y=runif(input$samples))
v <- bind_rows(v, results)
}
v %>% ggplot() + geom_line(aes(x=X, y=Y, colour=as.factor(Scenario)))
})
}
shinyApp(ui, server)