r - 在闪亮的应用程序中将轴值作为输入时不显示条形图
问题描述
我试图在下面闪亮的应用程序中创建一个条形图,我将在其中将y
值作为输入,但作为回报,我的图中没有条形图。可能是什么问题?
library(shiny)
library(shinydashboard)
library(shinydashboardPlus)
library(shinyWidgets)
library(dplyr)
library(plotly)
shinyApp(
ui = dashboardPagePlus(
header = dashboardHeaderPlus(title = "Social Media Metrics", titleWidth = 320
),
sidebar = dashboardSidebar(width = 320,
uiOutput("value")
),
body = dashboardBody(
plotlyOutput("plot")
)
),
server = function(input, output) {
page<-c("ONE","TWO","THREE")
network<-c("INSTAGRAM","FACEBOOK","FACEBOOK")
av<-c(3.5,4.2,8.7)
growth<-c(4,7,9)
av2<-c(3.5,7.2,4.7)
growth2<-c(4,7,9)
id <- rep("df1",3)
df1<-data.frame(page,network,av,growth,av2,growth2,id)
output$value<-renderUI({
pickerInput(
inputId = "val"
,
label = "Select Absolut Value"
,
choices = c("growth","growth2") #all rows of selected column
,
multiple = F, options = list(`actions-box` = TRUE)
)
})
output$plot<-renderPlotly({
fig <- plot_ly(df1, x = ~page, y = input$val, type = 'bar', name = 'SF Zoo')
})
}
)
解决方案
尝试这个。以您想要的样式调用变量的最佳方法是使用索引df[,var]
,这样您的输入将被正确呈现。这里的代码:
library(shiny)
library(shinydashboard)
library(shinydashboardPlus)
library(shinyWidgets)
library(dplyr)
library(plotly)
shinyApp(
ui = dashboardPagePlus(
header = dashboardHeaderPlus(title = "Social Media Metrics", titleWidth = 320
),
sidebar = dashboardSidebar(width = 320,
uiOutput("value")
),
body = dashboardBody(
plotlyOutput("plot")
)
),
server = function(input, output) {
page<-c("ONE","TWO","THREE")
network<-c("INSTAGRAM","FACEBOOK","FACEBOOK")
av<-c(3.5,4.2,8.7)
growth<-c(4,7,9)
av2<-c(3.5,7.2,4.7)
growth2<-c(4,7,9)
id <- rep("df1",3)
df1<-data.frame(page,network,av,growth,av2,growth2,id)
output$value<-renderUI({
pickerInput(
inputId = "val"
,
label = "Select Absolut Value"
,
choices = c("growth","growth2") #all rows of selected column
,
multiple = F, options = list(`actions-box` = TRUE)
)
})
output$plot<-renderPlotly({
fig <- plot_ly(x = df1[,'page'], y = df1[,input$val], type = 'bar', name = 'SF Zoo')
})
}
)
输出:
推荐阅读
- c# - 从 ajax 控制器接收到的数据为 NULL?
- python - pandas json_normalize 所有列都有嵌套字典展平
- css - 使用带有自定义 CSS 的表单构建器并需要帮助更改按钮对齐方式
- python - django - 我的表单不会保存添加的 M2M 对象。为什么?
- php - 如何制作基于工作日日历表的mysql考勤报告与员工考勤表连接
- html - 如何在边框中的链接之间添加间距
- python - 使用 DynamoDB 和 Lambda API 处理删除请求
- python - 如何在 BeautifulSoup 中使用 Python 仅打印这一行的日期?
- javascript - react-router - 从嵌套路由器导航到父路由
- vue.js - v-for in vue 更新数组中的所有对象,虽然键已经确定