Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/r/81.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
R 在应用程序中显示带有绘图的模式对话框_R_Shiny - Fatal编程技术网

R 在应用程序中显示带有绘图的模式对话框

R 在应用程序中显示带有绘图的模式对话框,r,shiny,R,Shiny,我有以下闪亮的应用程序: dates <- seq(as.Date("2018-01-01"), as.Date("2018-05-01"), by="days") point_duration = rnorm(n=length(dates), mean=6, sd=1) point_duration_bench = rnorm(n=length(dates), mean=5, sd=2) df <- data.frame(dates, point_duration, point_d

我有以下闪亮的应用程序:

dates <- seq(as.Date("2018-01-01"), as.Date("2018-05-01"), by="days")
point_duration = rnorm(n=length(dates), mean=6, sd=1)
point_duration_bench = rnorm(n=length(dates), mean=5, sd=2)
df <- data.frame(dates, point_duration, point_duration_bench)
df$week <- strftime(df$dates, format = "%V")
df$month <- strftime(df$dates, format = "%m")

current_day = Sys.Date()
current_week = strftime(current_day, format = "%V")
current_month = strftime(current_day, format = "%m")


library(shiny)
library(ggplot2)
library(plotly)
library(shinyBS)

UI <- fluidPage(
  actionButton("month","Show last week"),
  plotOutput("line_graph"),
  bsModal("modalExample", "Your plot", "go", size = "large",plotOutput("plot"),downloadButton('downloadPlot', 'Download'))

)
Server <- function(input, output) {

  observeEvent(input$month, {

    output$plot <- renderPlot({
      hist(50)
    })


  })

  output$line_graph <- renderPlot({
    ggplot(df, aes(x=dates, y=point_duration)) +
      geom_bar(stat = "identity") +
      geom_line(aes(x=dates, y = point_duration_bench), colour = "blue") + 
      geom_point() +
      labs(y="Amount of calls (#1000)",x="")
  })


}


shinyApp(ui = UI, server = Server)

dates您需要将模式输出连接到右侧按钮。当需要“一个月”才能工作时,您将其附加到“go”上。此外,我认为您不需要观察者,因为行为内置于
bsModal()
中。见工作代码:

dates <- seq(as.Date("2018-01-01"), as.Date("2018-05-01"), by="days")
point_duration = rnorm(n=length(dates), mean=6, sd=1)
point_duration_bench = rnorm(n=length(dates), mean=5, sd=2)
df <- data.frame(dates, point_duration, point_duration_bench)
df$week <- strftime(df$dates, format = "%V")
df$month <- strftime(df$dates, format = "%m")

current_day = Sys.Date()
current_week = strftime(current_day, format = "%V")
current_month = strftime(current_day, format = "%m")


library(shiny)
library(ggplot2)
library(plotly)
library(shinyBS)

UI <- fluidPage(
  actionButton("month","Show last week"),
  plotOutput("line_graph"),
  bsModal("modalExample", 
          "Your plot", 
          "month", # <----set the observer to the right button
          size = "large",
          plotOutput("plot"),
          downloadButton('downloadPlot', 'Download'))

)
Server <- function(input, output) {

      output$plot <- renderPlot({
        hist(50)
      })

  output$line_graph <- renderPlot({
    ggplot(df, aes(x=dates, y=point_duration)) +
      geom_bar(stat = "identity") +
      geom_line(aes(x=dates, y = point_duration_bench), colour = "blue") + 
      geom_point() +
      labs(y="Amount of calls (#1000)",x="")
  })


}


shinyApp(ui = UI, server = Server)

dates您需要将模式输出连接到右侧按钮。当需要“一个月”才能工作时,您将其附加到“go”上。此外,我认为您不需要观察者,因为行为内置于
bsModal()
中。见工作代码:

dates <- seq(as.Date("2018-01-01"), as.Date("2018-05-01"), by="days")
point_duration = rnorm(n=length(dates), mean=6, sd=1)
point_duration_bench = rnorm(n=length(dates), mean=5, sd=2)
df <- data.frame(dates, point_duration, point_duration_bench)
df$week <- strftime(df$dates, format = "%V")
df$month <- strftime(df$dates, format = "%m")

current_day = Sys.Date()
current_week = strftime(current_day, format = "%V")
current_month = strftime(current_day, format = "%m")


library(shiny)
library(ggplot2)
library(plotly)
library(shinyBS)

UI <- fluidPage(
  actionButton("month","Show last week"),
  plotOutput("line_graph"),
  bsModal("modalExample", 
          "Your plot", 
          "month", # <----set the observer to the right button
          size = "large",
          plotOutput("plot"),
          downloadButton('downloadPlot', 'Download'))

)
Server <- function(input, output) {

      output$plot <- renderPlot({
        hist(50)
      })

  output$line_graph <- renderPlot({
    ggplot(df, aes(x=dates, y=point_duration)) +
      geom_bar(stat = "identity") +
      geom_line(aes(x=dates, y = point_duration_bench), colour = "blue") + 
      geom_point() +
      labs(y="Amount of calls (#1000)",x="")
  })


}


shinyApp(ui = UI, server = Server)
日期