如何在本地数据帧的selectInput()中包含选项,而无需在R内存中预加载
除非我从如何在本地数据帧的selectInput()中包含选项,而无需在R内存中预加载,r,ggplot2,shiny,R,Ggplot2,Shiny,除非我从服务器预加载数据,否则我无法运行ShinyApp 如果在运行应用程序之前未读取数据,则会抛出错误: > runApp('example.R') Error in lapply(obj, function(val) { : object 'Data' not found 如果我选择所有代码并运行它,它就可以正常工作 有人能解释一下为什么以及如何修复它吗 这是我的密码: library(shiny) library(ggplot2) ui <- fluidPage( col
服务器
预加载数据
,否则我无法运行ShinyApp
如果在运行应用程序之前未读取数据
,则会抛出错误:
> runApp('example.R')
Error in lapply(obj, function(val) { : object 'Data' not found
如果我选择所有代码并运行它,它就可以正常工作
有人能解释一下为什么以及如何修复它吗
这是我的密码:
library(shiny)
library(ggplot2)
ui <- fluidPage(
column(12,selectInput("id_1","Choose the x axis",Data$Species)),
column(12,plotOutput("plot"))
)
server <- function(input, output, session) {
Data=iris
output$plot=renderPlot(
ggplot(Data[Data$Species==input$id_1,],aes(x=Sepal.Length,y=Petal.Length))+geom_point()+
labs(x="Sepal Length",y="Petal Length",title=paste0("Sepal Length vs Petal Length for ",input$id_1))+
theme(panel.background=element_blank())
)
}
shinyApp(ui = ui, server = server)
runApp('example.R')
库(闪亮)
图书馆(GG2)
ui您必须将selectInput放在renderUI函数内部的服务器函数中,因为它必须对所选输入做出反应。这在Ui中不起作用。您必须在renderplot函数中包含一个req(输入$id_1)
,因此它将等待直到选择某个对象
library(shiny)
library(ggplot2)
ui <- fluidPage(
column(6,uiOutput("uimod")),
column(6,plotOutput("plot"))
)
server <- function(input, output, session) {
Data=iris
output$uimod <- renderUI({
selectInput("id_1","Choose the x axis",Data$Species)
})
output$plot=renderPlot({
req(input$id_1)
ggplot(Data[Data$Species==input$id_1,],aes(x=Sepal.Length,y=Petal.Length))+
geom_point()+
labs(x="Sepal Length",y="Petal Length",
title=paste0("Sepal Length vs Petal Length for ",input$id_1))+
theme(panel.background=element_blank())
})
}
shinyApp(ui = ui, server = server)
库(闪亮)
图书馆(GG2)
谢谢!R只是代码所在文件的名称。当我在RStudio中单击Run时,它自动出现。谢谢你的回答。