简体   繁体   English

我是Shiny的新手,我想使用Iris数据集(这是R中的一个包)将一个简单的应用程序放在一起:

[英]I am new to shiny and I am trying to put a simple app together using the iris data set, which is a package in R:

I get the following error: 我收到以下错误:

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

when using the scripts below. 使用以下脚本时。 ui.R 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 和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 )

    })
 })

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"]] . 如果您使用诸如x-axis名称,则需要将其引用为input$'x-axis'或更简单的input[["x-axis"]] In your selectInput your names are your objects and vice versa. selectInput名称是对象,反之亦然。

# 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 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"]] )

  })
})

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 我是新手,我正在尝试制作一个可重复使用的简单应用 - I am new to shiny and I am trying to put a simple App for repeatable 我正在尝试制作一个简单的应用程序来比较两个 R 文件 - I am trying to make a simple app to compare two R files 在我使用来自原始数据集的信息创建新数据集时,如何简化此代码 (r)? - How can I simplify this code (r) in which I am using information from an original data set to create a new dataset? 我正在尝试在 R 中设计 shiny 应用程序,但我的应用程序无法从数据中选择变量名称。 我附上下面的代码 - I am trying to design a shiny app in R but my app is unable to pick variable names from the data. I am attaching the code below 我正在尝试使用Rfacebook包在R中获取我的facebook数据 - I am trying to get my facebook data in R using Rfacebook package 我是 r 的新手。我试图通过使用 for 循环使我的代码不那么复杂 - I am new to r. I am trying to make my code less complicated by using a for loop 我无法在R Shiny中设置数据表的列宽 - I am failing to set datatable column width in R Shiny R的新手。我正在尝试从mlbench软件包的Glass $ Fe中将0.00值添加.01。 - New to R. I am trying add .01 the 0.00 values in the Glass$Fe from the mlbench package 将我所在的数据表的哪一页保存到 R 中的变量中 - Save what page of a data table I am on into a variable in R shiny 在 R 中,data.frame 名称`iris`,我怎么知道它来自哪个 package? - In R, the data.frame name `iris`, how can i know which package it come from?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM