【问题标题】:Plot in shiny display in viewer in R studio instead of web browser在 R Studio 的查看器中而不是 Web 浏览器中以闪亮的显示进行绘图
【发布时间】:2015-08-22 23:59:19
【问题描述】:

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

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

现在所有内容都显示在 webbrowser 中,但在 R studio 的查看器中显示了一个绘图。它对在网络浏览器中正确显示的滑块输入有反应。我显然希望它在网络浏览器中显示所有内容

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

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

  })

})

    }

【问题讨论】:

  • 尝试在renderPlot末尾添加print(p)

标签: r data-visualization shiny


【解决方案1】:

这是一种解决方案:

在服务端,使用reactive而不是renderPlot,

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

并将 ggvis 图绑定到反应性语句之外的闪亮:

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

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

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

  )

另外请注意,你不需要在你的 ui 中库包。

希望对你有帮助

【讨论】:

    【解决方案2】:

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

    【讨论】:

      猜你喜欢
      • 2019-08-20
      • 2014-01-07
      • 2016-11-18
      • 2014-12-18
      • 1970-01-01
      • 2019-05-24
      • 2014-06-10
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多