我在列表中存储了一些对象。我有一个rmarkdown,并包括闪亮的应用程序来调用plotly对象。我收到错误消息:-[[:下标超出范围[无可用的堆栈跟踪]]错误。但是,当我运行实际代码时,出现错误:-UseMethod错误:没有适用于“ ggplotly”的适用方法应用于“ NULL”类的对象[无可用堆栈跟踪]。
我不在任何地方使用ggplotly。那么为什么会出现这个错误。
title: "Untitled"
author: "drishti"
date: "9/26/2018"
output: html_document
runtime: shiny
---
```{r setup, include=FALSE}
library(dplyr)
library(plotly)
knitr::opts_chunk$set(echo = TRUE)
```
```{r eruptions, echo=FALSE}
ggp1 <- plot_ly(iris,x = ~Sepal.Length,
y = ~Sepal.Width, type = 'scatter', mode = 'lines+markers',color =~ Species,
colors = c('olivedrab3', "plum", "palegreen4"))%>%
layout(
xaxis = list(title = "Sepal.Length"),
yaxis = list(title = "Sepal.Width")
)
plot1 <- list(c("Sepal.Length"),ggp1)
ggp2 <- plot_ly(iris,x = ~Petal.Length,
y = ~Petal.Width, type = 'scatter', mode = 'lines+markers',color =~ Species,
colors = c('olivedrab3', "plum", "palegreen4"))%>%
layout(
xaxis = list(title = "Petal.Length"),
yaxis = list(title = "Petal.Width")
)
plot2 <- list(c("Petal.Length"),ggp2)
model_list <- list(plot1,plot2)
```
## Embedded Application
```{r chunk1a, echo = FALSE,out.width = '8000px', out.height='800px'}
sample_data = function(dataset_name,given_model_list) {
shinyApp(
ui = fluidPage(
fluidRow(style = "padding-bottom: 20px;",
selectInput(inputId="Var_Sel", label="Variables to view", choices=c("Sepal.Length","Petal.Length"), selected = c("Sepal.Length"),
multiple = FALSE,selectize = TRUE, width = NULL, size = NULL),
# fluidRow(plotOutput('myplot')),
fluidRow(column(12,div(plotlyOutput("myplot", width = "100%", height = "200%",inline = F)),align="right"))
)
),
server = function(input, output, session) {
output$myplot <- renderPlotly({
if(is.null(input$Var_Sel)==FALSE){
for(i in 1:ncol(dataset_name)){
if(given_model_list[[i]][[1]] == input$Var_Sel){
print(given_model_list[[i]][[2]])
}
# else(given_model_list[[1]][[2]])
}
}
})
}
)
}
```
```{r chunk1b, echo = FALSE,out.width = '8000px', out.height='800px'}
sample_data(iris,model_list)
```