在 R studio 的查看器而不是网络浏览器中以闪亮的显示进行绘制

Plot in shiny display in viewer in R studio instead of web browser

这是我尝试做的第一个闪亮的应用程序。

之前我回顾了一些教程,当我 运行 外部应用程序时,所有这些都显示在网络浏览器中。

现在所有内容都显示在网络浏览器中,但在 R studio 的查看器中显示了一个图。它对在 web browser.I 中正确显示的 sliderInput 有反应,显然想让它在 webbrowser

中显示所有内容

可能是什么问题?我用钻石数据集做了一个可重现的例子 代码如下:

ui.R

 library(shiny)
library(ggvis)
library(ggplot2)
library(dplyr)

shinyUI(fluidPage(

  titlePanel("Analyza demografickych udajov Slovenskej republiky"),

  sidebarLayout(
    sidebarPanel(
      sliderInput("rok","Vyber rok ktory chces pozriet",min = min(diamonds$table),max = max(diamonds$table),value = 60,step = 1)

    ),



    mainPanel(
      tabsetPanel(type="tab",
                  tabPanel("plot",plotOutput("plot")),
                  tabPanel("Vzorka raw dat",tableOutput("table"))

      )
    )



  )))



 server.R

library(shiny)
library(ggvis)
library(ggplot2)
library(dplyr)

#read.csv("Demog.csv")
#p<-read.table(file = "Demog.csv",header = T,sep = ";")
#head(p)
#colnames(p)[2]<-"rok"
#colnames(p)[3]<-"pocet obyvatelov"

shinyServer(function(input,output){

  output$table<-renderTable({

    head(diamonds,10)
  })

  output$plot<-renderPlot({

    diamonds%>%filter(table==as.numeric(input$rok))%>%ggvis(~depth,~price)%>%layer_lines

  })

})

    }

这是一个解决方案:

在服务器中,使用 reactive 而不是 renderPlot,

  plot<-reactive({           
  diamonds%>%filter(table==as.numeric(input$rok))%>%ggvis(~depth,~price)%>%layer_lines
  })

并将 ggvis 图绑定到反应语句之外的 shiny:

plot%>% bind_shiny(plot_id="plot")

在 ui 中,您在主面板中的输出应该是:

      tabsetPanel(type="tab",
              tabPanel("plot",ggvisOutput("plot")),
              tabPanel("Vzorka raw dat",tableOutput("table"))

  )

另请注意,您不需要将包库存储在 ui。

希望对您有所帮助

这可能不适用于所有用户,但对于来自 Google 的用户:尝试关闭并重新打开 RStudio。我遇到了同样的问题(情节出现在 RStudio 而不是 Shiny 应用程序中),因为我有 运行 行 dev.off()。只需重新启动 RStudio 即可为我修复它。