在pyqt5中,当我单击“确定”按钮时,是否可以用刷新的底图替换图形画布?

时间:2019-02-02 13:18:36

标签: pyqt5 matplotlib-basemap redraw

library(shiny)
library(tidyverse)
library(lubridate)
library(glue)

ui <- fluidPage(

  # Application title
  titlePanel("Get NBA Scores"),

  # Select date
  sidebarLayout(
    sidebarPanel(
      dateInput(inputId = "date",
                label = "Select Date")
    ),

    mainPanel(
      textOutput("boxscores")
    )
  )
)

server <- function(input, output) {

  date <- reactiveValues()
  url <- reactiveValues()
  nba <- reactiveValues()

  # add leading zero to day
  observe(date$day <- ifelse(nchar(day(as.character(input$date))) == 1, paste0("0", day(as.character(input$date))), day(as.character(input$date))))

  # add leading zero to month
  observe(date$month <- ifelse(nchar(month(as.character(input$date))) == 1, paste0("0", month(as.character(input$date))), month(as.character(input$date))))

  # extract year
  observe(date$year <- year(as.character(input$date)))

  # create url
  observe(url$url1 <- glue("http://stats.nba.com/stats/scoreboard/?GameDate={date$month}/{date$day}/{date$year}&LeagueID=00&DayOffset=0"))

  #import data
  observe(nba$nba <- read_lines(url$url1))

  output$boxscores <- renderText({
    #plot raw data
    nba$nba
  })     
}

# Run the application 
shinyApp(ui = ui, server = server)

我将上面的画布绘制在output$boxscores <- renderText({ #plot url url$url1 }) 内。之后,我希望将此画布替换为在另一个函数中调用的刷新class PlotCanvas(FigureCanvas): def __init__(self, parent=None, width=50, height=40, dpi=100): fig = Figure(figsize=(width, height), dpi=dpi) self.axes = fig.add_subplot(111) FigureCanvas.__init__(self, fig) self.setParent(parent) FigureCanvas.setSizePolicy(self, QSizePolicy.Expanding, QSizePolicy.Expanding) FigureCanvas.updateGeometry(self) m = Basemap(ax=self.axes) m.drawcoastlines() m.fillcontinents(color=(255./255., 237./255., 163./255.) ) m.drawparallels(np.arange(-90.,91.,30.)) m.drawmeridians(np.arange(-180.,181.,60.)) m.drawmapboundary(fill_color='aqua') 。问题是,当我调用另一个函数并绘制刷新的地图时,它将在新窗口中打开,而不是替换旧窗口。

0 个答案:

没有答案