r - 带有 2 路离散变量的 Rshiny:为什么它不起作用?
问题描述
我想构建一个应用程序,允许我在 2 个离散变量图上切换变量,但执行时出现错误:
解析错误(文件,keep.source = FALSE,srcfile = src,编码 = enc):C:\Users\HH Portable\Desktop\Dossier R\Jeux de données\Thai/ui.R:13:0: 意外结束输入 11:
mainPanel(plotOutput('plot1')) 12:) ^ 警告:sourceUTF8 中的错误:错误采购 C:\Users\HHPORT~1\AppData\Local\Temp\RtmpekudB9\fileab876054ad6 [没有可用的堆栈跟踪]
library(shiny)
# ----- UI ----------------------------
pageWithSidebar(
headerPanel('Representer les variables'),
sidebarPanel(
selectInput('xcol', 'X Variable', names(the)),
selectInput('ycol', 'Y Variable', names(the)
),
mainPanel(plotOutput('plot1'))
)
#----- Server.r ------------------------------
library(shiny)
library(ggplot2)
# ---- Server ----------------------------------
# ---- ggplot with options ------------------------
server=shinyServer(function(input, output, session) {
output$plot1 <- renderPlot({
ggplot(the, aes(x=input$xcol, ..count..*100/sum(..count..))) +
geom_bar(aes(fill = input$ycol), position = "fill") +
geom_text(aes( label = scales::percent(..prop..),y= ..prop.. ),
stat= "count", vjust = -.5)
})
})
解决方案
尝试get()
在您的input$...
asinput$xcol
和input$ycol
are 字符串周围使用,并且aes()
不接受字符串。
下次您发布问题时,请添加一个可复制的小示例供其他人帮助您解决。
希望这可以帮助。
# ---- ggplot with options ------------------------
server=shinyServer(function(input, output, session) {
output$plot1 <- renderPlot({
ggplot(the, aes(x=get(input$xcol), ..count..*100/sum(..count..))) +
geom_bar(aes(fill = get(input$ycol)), position = "fill") +
geom_text(aes(label = scales::percent(..prop..),y= ..prop.. ),
stat= "count", vjust = -.5)
})
})
推荐阅读
- c# - 如何从 X509Certificate2 获取 RFC-1779 中的颁发者名称?
- angular - angular 5 多个路由器插座和子模块
- node.js - Mongoose:二进制子类型 4 到字符串
- bash - 解析作为另一个命令一部分的heredoc中的变量
- android - Cordova 应用在 Android 上几分钟后停止在后台播放音频
- typescript - 如何在元组中使用剩余参数?
- sql - 给定参与游戏的玩家,根据总分变化对玩家组合进行排名
- java - 自动填写注册表单字段
- typescript - 打字稿编译后导出的匿名函数名称丢失
- javascript - onmouseover 事件以更改另一个元素的 css - 两者都具有相同的动态 ID