如何在R中使用selectsize输入更新Ggplot
我想更新ggplot。这里我使用了plot函数,但是我想使用自动更新的ggplot。GGplot自动更新为selectsizeinput。怎么做??提前谢谢如何在R中使用selectsize输入更新Ggplot,r,ggplot2,shiny,R,Ggplot2,Shiny,我想更新ggplot。这里我使用了plot函数,但是我想使用自动更新的ggplot。GGplot自动更新为selectsizeinput。怎么做??提前谢谢 ui.r library(shiny) shinyUI(fluidPage( titlePanel("Multivariable plot"), sidebarLayout( sidebarPanel( fileInput("file", label = h3("Select CSV File")),
ui.r
library(shiny)
shinyUI(fluidPage(
titlePanel("Multivariable plot"),
sidebarLayout(
sidebarPanel(
fileInput("file", label = h3("Select CSV File")),
checkboxInput(inputId = 'header', label = 'col names', value = TRUE),
radioButtons(inputId = 'sep', label = 'Seperator', choices = c("comma"=',',"semi comma"=';'), selected = ','),
#checkboxGroupInput("choices1", label = h3("Wybierz Kolumny"), choices = NULL),
# there is combobox to pick column
selectInput("combobox", label = h3("x var"),choices = NULL),
#selectInput("combobox1", label = h3("y var"),choices = NULL)
selectizeInput("combobox1", label = h3("y var"), choices = NULL ,multiple = TRUE )
),
mainPanel(
uiOutput("tb")
)
)
))
server.r
function(input, output, session){
data <- reactive({
file1 <- input$file
if(is.null(file1)){return()}
dataSet <- read.csv(file=file1$datapath, sep=input$sep, header = input$header )
#updateCheckboxGroupInput(session, "choices1", choices = colnames(dataSet))
# this line updates selection in combobox
updateSelectInput(session, "combobox", choices = colnames(dataSet))
updateSelectizeInput(session, "combobox1", choices = colnames(dataSet), server = TRUE)
dataSet
})
output$table <- renderTable({
if(is.null(data())){return ()}
data()
})
output$multivarplot <- reactivePlot(function(){
x <- data()[, input$combobox]
ydat <- data.frame(data()[, input$combobox1])
xval<-data.frame(x,ydat)
# ggplot(xval, aes(x = reorder(x, -x), y = y))+geom_point(colour='red')
#g= ggplot(xval, aes(x,ydat[,1]))+geom_point(colour='red')
ny <- ncol(ydat)
par(mfcol=c(12,12),mfrow=c(1,1))
if(ny==1)
plot.default(x,ydat[,1],xaxt="n",col="blue")
axis(1, at=1:length(xval$x),labels = xval$x)
if (ny==2)
{ y1 <- ydat[,1]
y2 <- ydat[,2]
plot.default(x, y1, ylim = range(c(y1,y2)),col='red')
points(x,y2)}
})
output$tb <- renderUI({
tabsetPanel(tabPanel("Table", tableOutput("table")),
tabPanel("Plot",
plotOutput("multivarplot")))
})
}
ui.r
图书馆(闪亮)
shinyUI(fluidPage)(
titlePanel(“多变量图”),
侧边栏布局(
侧栏面板(
fileInput(“文件”,标签=h3(“选择CSV文件”),
checkboxInput(inputId='header',label='col names',value=TRUE),
单选按钮(inputId='sep',label='separator',choices=c(“逗号”=',',“半逗号”=';'),selected=','),
#checkboxGroupInput(“choices1”,label=h3(“Wybierz-Kolumny”),choices=NULL),
#有一个选择列的组合框
选择输入(“组合框”,标签=h3(“x变量”),选择=NULL),
#选择输入(“组合框1”,标签=h3(“y变量”),选择=NULL)
selectizeInput(“combobox1”,label=h3(“y变量”),choices=NULL,multiple=TRUE)
),
主面板(
输出(“tb”)
)
)
))
服务器.r
功能(输入、输出、会话){
数据这里是一个基于selectInput
和SelectizeInput
更新的ggplot
示例。据我所知,您希望在y轴上绘制多个变量,因此我使用了data.table
将数据融化为数据。table
有三列(x_var
,变量
,值
),即转换为长格式。该转换(以及任何其他计算)可以/应该移动到数据()
反应函数
library(shiny)
library(ggplot2)
library(data.table)
ui <- shinyUI(fluidPage(
titlePanel("Multivariable plot"),
sidebarLayout(
sidebarPanel(
fileInput("file", label = h3("Select CSV File")),
checkboxInput(inputId = 'header', label = 'col names', value = TRUE),
radioButtons(inputId = 'sep', label = 'Seperator',
choices = c("comma"=',',"semi comma"=';'), selected = ','),
selectInput("combobox", label = h3("x var"), choices = NULL),
selectizeInput("combobox1", label = h3("y var"), choices = NULL,
multiple = TRUE )
),
mainPanel(
tabsetPanel(tabPanel("Table", tableOutput("table")),
tabPanel("Plot", plotOutput("multivarplot")))
)
)
))
server <- function(input, output, session){
data <- reactive({
file1 <- input$file
if(is.null(file1)){return()}
dataSet <- read.csv(file=file1$datapath, sep=input$sep,
header = input$header)
updateSelectInput(session, "combobox", choices = colnames(dataSet))
updateSelectizeInput(session, "combobox1", choices = colnames(dataSet),
server = TRUE)
dataSet
})
output$table <- renderTable({
data()
})
output$multivarplot <- renderPlot({
dt <- data.table(data())
x_var <- input$combobox
y_var <- input$combobox1
if (!is.null(x_var) & !is.null(y_var)) {
dt_melt <- melt(dt, id.vars = x_var, measure.vars = y_var)
ggplot(dt_melt, aes_string(x = x_var, y = "value", group = "variable",
colour = "variable")) + geom_point(size = 3)
}
})
}
shinyApp(ui = ui, server = server)
库(闪亮)
图书馆(GG2)
库(数据表)
ui请做一个简单的例子,再现你不喜欢的行为,并提供详细的期望。