这是我尝试做的第一个闪亮的应用程序。
之前我查看了一些教程,当我在外部运行app时,所有这些都在Web浏览器中显示。
现在所有内容都显示在webbrowser中,但是在R studio的查看器中显示的图表。它对于在网页浏览器中正确显示的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
})
})
}
答案 0 :(得分:0)
这是一个解决方案:
在服务器中,使用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中存储软件包。
希望这有帮助
答案 1 :(得分:0)
这可能不适用于所有用户,但对于那些来自Google的用户:尝试关闭并重新打开RStudio。我有同样的问题(情节出现在RStudio而不是Shiny应用程序),因为我已经运行了dev.off()行。只需重新启动RStudio即可为我修复它。