【发布时间】:2018-05-15 20:51:41
【问题描述】:
我正在尝试在闪亮的应用程序中绘制一个简单的直方图。在应用程序外部(在 R 脚本中),图表绘制没有任何问题,(see here)但相同的代码从应用程序内部生成一个看起来很奇怪的图表(see the wrong graph here)
你能帮我找出问题所在吗?数据集链接:https://drive.google.com/open?id=1ITK0lTWm_mkb9KonHLq4nuKDv-PBUDeR
library(ggplot2)
library(ggthemes)
library(scales)
library(shiny)
# read data
cso_corruption <- read.csv("cso_corruption.csv", header = T, sep = ",")
ui <- fluidPage(
sidebarLayout(
sidebarPanel(
radioButtons(inputId = "x",label ="Measurement Type",choices =
c("freq_business", "freq_cso"), selected = NULL)
),
mainPanel(
plotOutput(outputId = "hist")
)
)
)
server <- function(input, output) {
output$hist <- renderPlot(ggplot(data = na.omit(cso_corruption), aes(x=input$x)) +
geom_histogram(fill="lightgreen", stat="count"))
}
shinyApp(ui = ui, server = server)
【问题讨论】:
-
为什么不发布您的输出/日志或我们可以用来帮助您的任何其他信息?
-
当您说“代码失败”时,究竟是什么意思?您是否收到错误消息?如果是这样,您也需要共享该信息。
-
@ytpillai - 我已经编辑了帖子并添加了图表。请帮助
-
@MrFlick - 没有错误消息,只是一个错误的情节。我现在已经在帖子中添加了图表。
-
@umbi 不,我不想。 JK,顺便说一句,您使用的直方图将条形图粘在一起。我建议您检查一下您没有在 renderPlot 中复制数据