我收到以下错误:
Error in $.shinyoutput(*tmp*, X) :
Reading objects from shinyoutput object not allowed
使用以下脚本时。 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")
)
)
))
和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 )
})
})
答案 0 :(得分:1)
您使用的名称不合适。如果您使用x-axis
等名称,则需要将其称为input$'x-axis'
或更简单input[["x-axis"]]
。在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
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"]] )
})
})