【发布时间】:2019-01-21 17:14:10
【问题描述】:
我是 Shiny 的绝对初学者,因此非常感谢您的耐心和对我的问题的任何建议。这是我用来输出 ggplot 的服务器函数,它可以独立工作,但在我更改输入时根本不会改变:
server <- function(input, output) {
output$plooot<-renderPlot({
df = df %>%
group_by(input$Category,Type) %>%
summarise(Distribution=sum(Distribution))
ggplot(df,aes(input$Category,Distribution,fill=Type))+geom_bar(stat="identity",position="dodge")})
}
shinyApp(ui=ui,server=server)
这是我的 ui 函数,仅供参考:
ui <- fluidPage(
titlePanel("chart"),
# Generate a row with a sidebar
sidebarLayout(
# Define the sidebar with one input
sidebarPanel(
selectInput("Category","Category:",choices=c("a","b","c","d","e","f")),
selectInput("a","a:", choices=unique(Table$a), selected="All"),
selectInput("b","b:", choices=unique(Table$b), selected="All"),
selectInput("c","c:", choices=unique(Table$c), selected="All"),
selectInput("d","d:", choices=unique(Table$d), selected="All"),
selectInput("e","e:", choices=unique(Table$e), selected="All"),
selectInput("f","f:", choices=unique(Table$f), selected="All")
),
# Create a spot for the barplot
mainPanel(
plotOutput("plooot")
)
)
)
很遗憾,出于法律原因,我无法发布数据,但这里有两个图表,我想要什么与我拥有什么:
这可能是一个非常基本的错误,但我无法理解我做错了什么。
【问题讨论】:
-
group_by(input$Category,Type)需要一个实际的列(使用 NSE),而不是character(这是从input$Category获得的)。寻找dplyr动词的标准评估版本。 -
尝试
ic <- enquo(input$Category),然后尝试... %>% group_by(!!ic,Type) ...。 -
我不确定您如何在应用程序中存储数据 (df),但
df = df %>% ....可能会在您生成绘图时覆盖您的数据,从而无法在输入后更新绘图。 -
mistersunnyd,因为您是新来的(嗯,不是新来的,但您在 SO 的时间还没有接受答案)......当您找到充分解决您问题的答案时,请"accept" it.