  C RUBY-ON-RAILS MYSQL ASP.NET DEVELOPMENT RUBY .NET LINUX SQL-SERVER REGEX WINDOWS ALGORITHM ECLIPSE VISUAL-STUDIO STRING SVN PERFORMANCE APACHE-FLEX UNIT-TESTING SECURITY LINQ UNIX MATH EMAIL OOP LANGUAGE-AGNOSTIC VB6 MSBUILD # subset data and plot this subsetted data with Shiny  » r » subset data and plot this subsetted data with Shiny

By : ChuTing
Date : November 18 2020, 11:13 AM
may help you . If I have the following data frame: , You have superfluous comma's in your ui.R: code :
``````shinyUI(pageWithSidebar(
sidebarPanel(
selectInput("proj", "Project:",ulist) # remove comma here
),
mainPanel(
plotOutput("testPlot") # remove comma here
)
) )
`````` ## How subset a data frame by a factor and repeat a plot for each subset?

By : Raghav_Core_Develope
Date : March 29 2020, 07:55 AM
Hope this helps Because you want to split up the dataset and make a plot for each level of a factor, I would approach this with one of the split-apply-return tools from the plyr package.
Here is a toy example using the mtcars dataset. I first create the plot and name it p, then use dlply to split the dataset by a factor and return a plot for each level. I'm taking advantage of %+% from ggplot2 to replace the data.frame in a plot.
code :
``````p = ggplot(data = mtcars, aes(x = wt, y = mpg)) +
geom_line()

require(plyr)
dlply(mtcars, .(cyl), function(x) p %+% x)
``````
``````plots = dlply(mtcars, .(cyl), function(x) p %+% x)
plots
``````
``````dlply(mtcars, .(cyl), function(x) p %+% x + facet_wrap(~cyl))
``````
``````pdf()
plots
dev.off()
``````
``````library(dplyr)
plots = mtcars %>%
group_by(cyl) %>%
do(plots = p %+% . + facet_wrap(~cyl))

Source: local data frame [3 x 2]
Groups: <by row>

cyl           plots
1   4 <S3:gg, ggplot>
2   6 <S3:gg, ggplot>
3   8 <S3:gg, ggplot>
``````
``````plots\$plots
``````
``````pdf()
plots\$plots
dev.off()
`````` ## Create input\$selection to subset data AND radiobuttons to choose plot type in Shiny

By : user2956140
Date : November 22 2020, 10:54 AM
this will help I've been trying to utilize shiny to create several visualizations for several different classes of data. Last night I was able to subset data but I do not know how to switch plot types with this data. I have the following data frame: , You need to use reactive functions.
ui.R:
code :
``````library(shiny)
ulist=levels(cd\$Project)
names(ulist) = ulist
shinyUI(pageWithSidebar(
sidebarPanel(
list("A", "B", "C")),
selectInput("proj", "Project:",ulist)
),
mainPanel(
plotOutput("testPlot")
)
)
)
``````
``````library(shiny)
library(ggplot2)
library(lattice)

# Define shiny server
shinyServer(function(input, output) {
pdata <- reactive({
subset(cd, Project==input\$proj)
}
)
plotType <- reactive({
switch(input\$pType,
A = hist,
B = barplot,
C = pie)
})
output\$testPlot <- renderPlot({
plotType()(pdata()[["Hours"]])
})
})
`````` ## Select row(s) from a summary data table and use cell value to subset original data and create a new data table in Shiny

By : ÅbÐül RëhmÅn Ålï
Date : March 29 2020, 07:55 AM
around this issue I have created a summary table from iris data set and when i select any row from that datatable I want to use the row selected to subset main data and later publish that subset data as a datatable. , Your error message most probably comes from this line
code :
``````selected_column <-  df1[as.integer(input\$summarytable_rows_selected),]\$get(input\$group)
``````
``````selected_column <-  df1()[as.integer(input\$summarytable_rows_selected),][[input\$group]]
``````
``````df[df\$get(input\$group) %in% selected_column, ]
``````
``````df[df[[input\$group]] %in% selected_column, ]
`````` ## Shiny/ggvis Reactivity to Subset Plot Data

By : user4827738
Date : March 29 2020, 07:55 AM
I hope this helps . Further search would indicate that this is a known bug for ggvis: https://github.com/rstudio/ggvis/issues/71 ## R subset function: why does it include non subsetted data?

By : asasher
Date : March 29 2020, 07:55 AM
wish of those help Because us12 is a data.frame in which nationality and response columns are factors, including all the levels of the original data.frame.
In fact, table(us12) returns you the counts, and as you can see, all the counts for nationalities different from United States are zero. 