【发布时间】:2019-01-27 14:45:20
【问题描述】:
我是 Shiny 的新手,所以在 ui 和服务器如何相互交谈时遇到了麻烦。我想创建一个带有动态过滤器参数的ggplot2 条形图,这样我就可以在textInput 小部件中输入一个单词,这样条形图就会发生变化。
数据:
我正在处理来自 300 个文档的大约 50,000 个单词,这就是我需要 textInput 的原因,但这里有一些示例数据:
library(tidyverse)
library(shiny)
example_df <- tibble::tribble(
~doc, ~word, ~n,
"A", "sustainable", 5L,
"A", "migrants", 2L,
"A", "building", 4L,
"B", "sustainable", 2L,
"B", "together", 1L,
"B", "building", 5L
)
用户界面:
ui <- fluidPage(
sidebarLayout(
sidebarPanel(
textInput(inputId = "word",
label = "Word:",
value = "sustainable"),
),
mainPanel(
plotOutput(outputId = "barchart")
)
)
)
使用这段代码,我已经遇到了一个我不明白的错误:
Error in tag("form", list(...)) : argument is missing, with no default
服务器:
server <- function(input, output) {
output$barchart <- renderPlot({
example_df %>%
filter(word == input) %>%
arrange(desc(n)) %>%
head(20) %>%
ggplot(aes(x = reorder(doc, n),
y = n)) +
geom_col() +
theme_minimal()
})
}
我知道这个闪亮的代码可能很疯狂,但非常感谢所有帮助!
【问题讨论】:
-
可能还有其他问题,但您在
textInput()后面有一个不需要的逗号
标签: r shiny bar-chart shiny-reactivity