[英]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.