阴谋和袖扣在Anaconda中不起作用

时间:2018-08-24 06:26:09

标签: python plotly

我一直在做一门有关数据科学和机器学习的课程,在其中一课中,它要求我下载并使用plotly和袖扣。我已成功下载并安装了它们,也已成功导入了它们。但是,当尝试通过iplot使用它们时,却给了我一个错误。下面我附上了该错误的屏幕截图,所以我想知道如何解决此错误,并使用plotly和袖扣没有任何问题。

我编写的代码:

library(shiny)
library(DT)
library(rhandsontable)
#library(tidyverse)

ui <- navbarPage(
  "Application",
  tabPanel("Booklets",
           sidebarLayout(
             sidebarPanel(
               uiOutput("tex2"),
               rHandsontableOutput("hot3")
             ),
             mainPanel(
               fluidRow(
                 wellPanel(
                   fluidRow(
                     column(4,
                            DT::dataTableOutput("hot5")
                     ),
                     column(4,
                            fluidRow(
                              uiOutput("book3"),
                              uiOutput("book6")

                            ),
                            fluidRow(
                              uiOutput("book1"),
                              uiOutput("book10"),
                              uiOutput("book11")
                            ),
                            fluidRow(actionButton("submit","submit"))
                     )
                   ))
               )
             )
           )
  )
)
#server
server <- function(input, output, session) {

  rv<-reactiveValues()

  output$tex2<-renderUI({
    numericInput("text2", "#tests", value = 1, min=1)
  })

  output$book1<-renderUI({
    numericInput("bk1",
                 "Items in test",
                 value = 1,
                 min = 1)
  })

  output$book3<-renderUI({

    selectInput("bk3",
                "Label",
                choices=(paste("Test",1:input$text2)))

  })


  output$book6<-renderUI({
    textInput("bk6", "Change to",
              value=NULL
    )
  })


  output$book10<-renderUI({
    # changed from selectize
    selectizeInput(
      "bk10", "Select Items", choices =1:10000,multiple =T,selected = 1,
      options = list(maxItems = input$bk1))#changed from
  })
  output$book11<-renderUI({
    textInput("bk11", "Items chosen",
              value = nrow(rt5())
    )
  })

  #rt4<-reactive({
  observe({
    req(input$text2)

    rv$rt4 = data.frame(
      SNo = rep(TRUE, input$text2),
      Test=paste(1:input$text2),
      Label=paste("Test",1:input$text2),
      Avail=1L,
      Sel =as.integer(rep.int(0,input$text2)),
      stringsAsFactors = FALSE)
  })

  observeEvent(input$submit,{

 # rt4 <- reactive({
    if (is.null( rv$rt4))
      return(NULL)

    if(!is.null(input$bk6) && input$bk6!=""){
      rv$rt4[ rv$rt4$Label==input$bk3, "Avail"] <- input$bk1
      rv$rt4[ rv$rt4$Label==(input$bk3), "Sel"] <- length(input$hot5_rows_selected)

      rv$rt4[ rv$rt4$Label==input$bk3, "Label"] <- input$bk6
    }
    # if(!is.null(input$hot5_rows_selected) && input$hot5_rows_selected!=""){
    #
    # }
  })

  observeEvent(input$submit,{

    updateSelectInput(session,"bk3","Label", choices=rv$rt4$Label)
  }
  )


  rt55<-reactive({
    DF=data.frame(
      Id=  input$bk10,
      Label=paste("Item",input$bk10),
      Pf=0,
      stringsAsFactors = FALSE
    )
  })

  rt5<-reactive({
    DF=data.frame(
      Id=  input$bk10,
      Label=paste("Item",input$bk10),
      Pf=0,
      stringsAsFactors = FALSE
    )
    cbind(id=rowSelected(), DF)
  })

  rowSelected <- reactive({
    x <- numeric(nrow(rt55()))
    x[input$hot5_rows_selected] <- 1
    x
  })

  output$hot5 <- renderDT(datatable(rt5()[,-1],
                                    selection = list(mode = "multiple",
                                                     selected = (1:nrow(rt5()[,-1]))[as.logical(rowSelected())],
                                                     target = "row"),rownames = F)
  )

  output$hot3 <-renderRHandsontable({
    req(input$text2)
    rhandsontable(rv$rt4)
  })
}
shinyApp(ui,server)

我得到的错误:

import pandas as pd
import numpy as np
%matplotlib inline
from plotly import __version__
from plotly.offline import download_plotlyjs, init_notebook_mode, plot, iplot
print(__version__)
init_notebook_mode(connected=True)
cf.go_offline()
df = pd.DataFrame(np.random.randn(100,4),columns='A B C D'.split())
df.iplot(kind='scatter',x='A',y='B',mode='markers',size=10)

3 个答案:

答案 0 :(得分:2)

执行以下代码会得到什么?

import plotly
import plotly.plotly as py
import plotly.graph_objs as go
import numpy as np
import pandas as pd
import numpy as np
%matplotlib inline
from plotly import __version__
from plotly.offline import download_plotlyjs, init_notebook_mode, plot, iplot
import cufflinks as cf
print(__version__)
init_notebook_mode(connected=True)
cf.go_offline()

df = pd.DataFrame(np.random.randn(100,4),columns='A B C D'.split())
trace = go.Scatter(x = df['A'], y = df['B'], mode = 'markers')
data = [trace]
fig = go.Figure(data=data)
plotly.offline.plot(fig)

有了plotly.offline.plot,一切正常,但我认为您只需要plotly.plotly.iplot。 谷歌搜索之后,我发现possible solution到了-只需将您的可打印版本降级:

pip uninstall plotly
pip install plotly==2.7.0

我检查了最新版本plotly-它是3.1.1,此错误也在这里。所以我想使用plotly <3.0.0版本可以解决您的问题

答案 1 :(得分:0)

截至2019年的更新解决方案:

这是一个错误,如果您的袖扣版本为0.13或更旧版本,而该版本与plotly 3.0不兼容。这可能是因为您是从conda或其他来源而不是通过pip安装的。

要解决此问题,请运行:

pip install cufflinks --upgrade

答案 2 :(得分:0)

根据@Idodo的总结,您必须在“ Anaconda Prompt”中编写以下代码行,请以管理员身份打开此行。

用于绘图库

conda install -c plotly plotly 

用于袖扣库

conda install -c conda-forge python-cufflinks 

然后升级袖扣

pip install cufflinks --upgrade