首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >我是个新手,我正在试着用虹膜数据集把一个简单的应用程序放在一起,这是一个R语言的包:

我是个新手,我正在试着用虹膜数据集把一个简单的应用程序放在一起,这是一个R语言的包:
EN

Stack Overflow用户
提问于 2015-02-06 18:13:51
回答 1查看 667关注 0票数 1

我得到以下错误:

代码语言:javascript
复制
Error in $.shinyoutput(*tmp*, X) : 
  Reading objects from shinyoutput object not allowed

使用下面的脚本时。ui.R

代码语言:javascript
复制
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")
    )
  )
))

和server.R

代码语言:javascript
复制
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 )

    })
 })
EN

回答 1

Stack Overflow用户

发布于 2015-02-06 18:51:02

您使用了不恰当的名称。如果您使用诸如x-axis之类的名称,则需要将其称为input$'x-axis'或更简单的input[["x-axis"]]。在selectInput中,你的名字就是你的对象,反之亦然。

代码语言:javascript
复制
# 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

代码语言:javascript
复制
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"]] )

  })
})
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/28363337

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档