到目前为止,我有一个工作正常的复杂函数.我需要让非程序员在工作中使用这个功能,我开始创建一个简单的应用程序.
问题是,在我的用户定义函数中,我创建了一个作为对象存储的图形,以及作为数据帧存储的最终输出,然后返回.所有重要的结果都会在以后导出.所有这些都运行得很好. 但我希望我的最终图形绘制在Rshiny 的范围内.
我试图举出一个我仍在为之奋斗的小例子
test_function <- function(x){
new_data <- iris[iris$Species==x,] %>% droplevels()
write.csv(new_data,"test.csv")
new_plot <- plot(new_data$Sepal.Length,new_data$Petal.Length)
new_plot %>% plot
return(new_data)
} # I would run my code outside the app, I would see the plots in my Rstudio plot panel.
ui <- fluidPage(
# Application title
titlePanel("Test for 2022"),
# Sidebar with a slider input for number of bins
sidebarLayout(
sidebarPanel(
textInput("Species",
"Insert species name"),
actionButton(inputId = "input_action", label = "Run")
),
mainPanel(
plotOutput("plot")
)
)
)
server <- function(input, output) {
observeEvent(input$input_action, {
taxa <- input$Species
test_function(taxa)
output$plot <- renderPlot({
plot(test_function(input$Species))})
})
}
ShinyApp(UI,服务器)#但这里没有图形,代码运行,..一切如愿以偿地出口.我需要更改什么才能在我更改输入名称时获得新的绘图?