gpt4 book ai didi

r - GoogleVis 和 Shiny

转载 作者:行者123 更新时间:2023-12-02 04:24:36 25 4
gpt4 key购买 nike

我正在尝试创建一个 Shiny 的应用程序,将数据绘制为气泡图。我遇到的问题是子集。用户可以通过一些输入来选择数据子集。下面是我的一些代码。我不断收到此错误: Error in data.frame(NA= NULL, var6 = c(1.95, 1.62, 1.57, 1.44, 1.7, : 参数暗示不同的行数: 0,第736章

全局.R

#Import File From Computer
data <- read.csv("C:\\Users\\User\\Documents\\Project\\Shiny\\data.csv", header=TRUE)

可以使用以下命令复制数据:

Type <- c('A','A','A','B','B','B','C','C','C',)
Date <- as.Date(c('2010-11-1','2008-3-25','2007-3-14','2010-11-1','2008-3-25','2007-3-14','2010-11-1','2008-3-25','2007-3-14'))
Run <- c('RUN1','RUN2','RUN3','RUN1','RUN2','RUN3','RUN1','RUN2','RUN3')
Var1 <- c(1,2,3,4,5,6,7,8,9)
Var2 <- c(2,4,6,8,10,12,14,16,18)
Var3 <- c(3,6,9,12,15,18,21,24,27)
Var4 <- c(4,8,12,16,20,24,28,32,36)
data <- data.frame(Type,Date,Run,Var1,Var2,Var3,Var4)

ui.R

library(googleVis)

shinyUI(fluidPage(
titlePanel("Visualization Tool"),
sidebarLayout(
headerPanel('Data Selection'),
sidebarPanel(
selectInput('x', 'X Variable', names(data)),
selectInput('y', 'Y Variable', names(data)),
selectInput('z', 'Z Variable', names(data),
selected=names(data)[[5]]),

checkboxGroupInput('Type', 'Type', c(
"A"="A",
"B"="B",
"C"="C")),
checkboxGroupInput('Run', 'Run', c(
"RUN1"="RUN1",
"RUN2"="RUN2",
"RUN3"="RUN3"))

)),

mainPanel(htmlOutput(("chart"))
)
))

服务器.R

library(shiny)
library(googleVis)

shinyServer(function(input, output){
datasetInput <- total
output$chart <- renderGvis({
gvisBubbleChart(datasetInput, idvar=input$Name, xvar=input$x, yvar=input$y,
color=input$Name, sizevar=input$z)
})
})

最佳答案

我明白了...在 ui.R 中,我将名称更改为向量

xx<-c("Type"="Type", "Date"="Date", "Run"="Run","Var1"="Var1","Var2"="Var2","Var3"="Var3","Var4"="Var4")

ui.R 变为:

library(googleVis)

shinyUI(fluidPage(
titlePanel("Visualization Tool"),
sidebarLayout(
headerPanel('Data Selection'),
sidebarPanel(
selectInput('x', 'X Variable', xx),
selectInput('y', 'Y Variable', xx),
selectInput('z', 'Z Variable', xx),


checkboxGroupInput('Type', 'Type', c(
"A"="A",
"B"="B",
"C"="C")),
checkboxGroupInput('Run', 'Run', c(
"RUN1"="RUN1",
"RUN2"="RUN2",
"RUN3"="RUN3"))

)),

mainPanel(htmlOutput(("chart"))
)
))

server.R 变为:

library(shiny)
library(googleVis)

shinyServer(function(input, output){
datasetInput <- reactive({data[data$Type %in% input$Type,]})
output$chart <- renderGvis({
gvisBubbleChart(datasetInput(), idvar="Type", xvar=input$x, yvar=input$y,
color="Type", sizevar=input$z)
})

})

关于r - GoogleVis 和 Shiny,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25017652/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com