1

I get the following error:

Error in $.shinyoutput(*tmp*, X) : 
  Reading objects from shinyoutput object not allowed

when using the scripts below. ui.R

library(shiny)
shinyUI(fluidPage(
  titlePanel("Dynamic user interface-RenderUI"),
  sidebarLayout(
    sidebarPanel(
      selectInput("data", "Select the Database of your choice",
                  c("iris"="Iris","mtcars"="mt","trees"="tree")),
      br(),
      helpText("The folowing SelectInput drop down choices are dynamically polulated based on dataset selected"),
      br(),
      uiOutput("X-Axis"),#X-Axis is coming from renderui inserver
      br(),
      uiOutput("Y-Axis")#Y-Axis is coming from renderui inserver
    ),
       mainPanel(
      plotOutput("p")
    )
  )
))

and server.R

library(shiny)
shinyServer(function(input, output) {
  var <-reactive({
    switch(input$data,
    "iris"=names(iris),
    "mtcars"=names(mtcars),
    "trees"=names(trees)
    )

  })

  output$X-Axis <- renderUI({
            selectInput("x-axis", "Select the X-Axis variable",choices = var())


  })


  output$Y-Axis <- renderUI({

    selectInput("y-axis", "Select the Y-Axis variable",choices = var())


  })
    output$p <- renderPlot({

    attach(get(input$data))

    plot(x=get(input$x-axis),y=get(input$y-axis),xlab =input$x-axis,ylab = input$y-axis )

    })
 })
Sufiyan Ghori
  • 18,164
  • 14
  • 82
  • 110
Amritham
  • 51
  • 3

1 Answers1

1

You are using inappropriate names. If you use names such as x-axis you will need to refer to them as input$'x-axis' or maybe easier input[["x-axis"]]. In your selectInput your names are your objects and vice versa.

# UI.r

library(shiny)
shinyUI(fluidPage(
  titlePanel("Dynamic user interface-RenderUI"),
  sidebarLayout(
    sidebarPanel(
      selectInput("data", "Select the Database of your choice",
                  c("Iris"="iris","mt"="mtcars","tree"="trees")),
      br(),
      helpText("The folowing SelectInput drop down choices are dynamically polulated based on dataset selected"),
      br(),
      uiOutput("X-Axis"),#X-Axis is coming from renderui inserver
      br(),
      uiOutput("Y-Axis")#Y-Axis is coming from renderui inserver
    ),
    mainPanel(
      plotOutput("p")
    )
  )
))

server.R

library(shiny)
shinyServer(function(input, output) {
  var <-reactive({
    switch(input$data,
           "iris"=names(iris),
           "mtcars"=names(mtcars),
           "trees"=names(trees)
    )

  })

  output[["X-Axis"]] <- renderUI({
    selectInput("x-axis", "Select the X-Axis variable",choices = var())


  })


  output[["Y-Axis"]] <- renderUI({

    selectInput("y-axis", "Select the Y-Axis variable",choices = var())


  })
  output$p <- renderPlot({

    attach(get(input$data))

    plot(x=get(input[["x-axis"]]),y=get(input[["y-axis"]]),xlab =input[["x-axis"]],ylab = input[["y-axis"]] )

  })
})
jdharrison
  • 30,085
  • 4
  • 77
  • 89
  • jdharrison, Could you please look at these two questions? https://stackoverflow.com/questions/61569169/plot-scatterplot-on-a-map-in-shiny https://stackoverflow.com/questions/61559805/link-selectinput-with-sliderinput-in-shiny?noredirect=1#comment108896301_61559805 –  May 03 '20 at 04:11