r

How to import an .R file and assign an alias to it? Like import myfile.R as mf

大憨熊 提交于 2021-02-18 08:17:15
问题 R beginner here, who really misses Python's import pandas as pd import my_file_which_is_just_a_file_not_a_package as mf out = mf.my_cool_function() I have found a way to implement something similar to the former (assigning an alias to a package), but how to do the latter, i.e. how to assign an alias to an .R file (not a package) you are importing? E.g. you have put some functions you use frequently into a separate .R file, or you are dividing your program into multiple .R files to keep things

How to change a plot when hovering over elements in Shiny?

杀马特。学长 韩版系。学妹 提交于 2021-02-18 08:11:12
问题 I am searching for a solution to change a plot in a Shiny app when the user is hovering over a hyperlink in the same panel. Here is a simple example: library(shiny) words <- sort(sapply(1:50, USE.NAMES = F, FUN = function (x) paste(sample(letters, 15), collapse = "")), decreasing = T) dat <- data.frame(words, f = sort(rgamma(50, shape = 5, scale = 1))) ui <- pageWithSidebar( headerPanel("Playground"), sidebarPanel(), mainPanel( uiOutput("links"), plotOutput("out.plot") ) ) server <- function

How to change a plot when hovering over elements in Shiny?

你。 提交于 2021-02-18 08:11:07
问题 I am searching for a solution to change a plot in a Shiny app when the user is hovering over a hyperlink in the same panel. Here is a simple example: library(shiny) words <- sort(sapply(1:50, USE.NAMES = F, FUN = function (x) paste(sample(letters, 15), collapse = "")), decreasing = T) dat <- data.frame(words, f = sort(rgamma(50, shape = 5, scale = 1))) ui <- pageWithSidebar( headerPanel("Playground"), sidebarPanel(), mainPanel( uiOutput("links"), plotOutput("out.plot") ) ) server <- function

Add a new row with the existing data frame in shiny R by using action button

让人想犯罪 __ 提交于 2021-02-18 08:08:26
问题 I am building a shiny form which will take data from the textInput field and combined those input with a text file (which will be uploaded by file input) and show the output in the main panel. There is an action button to update the data for the first time (take the data from text input and merge with the processed text file) and I added another action button for add new data (the purpose of this Add new data to add a new set of data as row with the existing one, The new set of data will be

How do I change the color of an infobox in shinydashboard based on the value displayed

眉间皱痕 提交于 2021-02-18 08:07:10
问题 I am trying to creating a simple weather display, which will change the infobox color based on the temperature. The color value is correct as it displays correctly, but the color parameter will not recognize the color. It reports Error in validateColor(color) : Invalid color: . Valid colors are: red, yellow, aqua, blue, light-blue, green, navy, teal, olive, lime, orange, fuchsia, purple, maroon, black. In addition: Warning message: In if (color %in% validColors) { : the condition has length >

Generate table with side-by-side node models of `partykit:mob()` object

有些话、适合烂在心里 提交于 2021-02-18 07:51:08
问题 Let's say I fit a model using partykit:mob() . Afterward, I would like to generate a side-by-side table with all the nodes (including the model fitted using the whole sample). Here I attempted to do it using stargazer() , but other ways are more than welcome. Below an example and attempts to get the table. library("partykit") require("mlbench") ## Pima Indians diabetes data data("PimaIndiansDiabetes", package = "mlbench") ## a simple basic fitting function (of type 1) for a logistic

RPostgreSQL Cannot Close Connections

余生颓废 提交于 2021-02-18 07:26:33
问题 I have a shiny app that connects to a database using RPostgreSQL . At the end of the app the connection is closed and the driver should be unloaded but I get an error, warning me that the connection is not closed. The code looks something like this: # in the app.R file, but not in the server function: drv <- dbDriver("PostgreSQL") con <- dbConnect(drv, dbname = "database1", host = "localhost", port = 5432, user = "user", password = "pw") # in the server function: foo <- dbGetQuery(con,

Extract rows with highest and lowest values from a data frame

ぐ巨炮叔叔 提交于 2021-02-18 07:01:47
问题 I'm quite new to R, I use it mainly for visualising statistics using ggplot2 library. Now I have faced a problem with data preparation. I need to write a function, that will remove some number (2, 5 or 10) rows from a data frame that have highest and lowest values in specified column and put them into another data frame, and do this for each combination of two factors (in my case: for each day and server). Up to this point, I have done the following steps (MWE using esoph example dataset). I

Order multiple variables in ggplot2

夙愿已清 提交于 2021-02-18 06:27:36
问题 I'm attempting to group variables within variables and sort in descending order. mydf region airport value MIA FLL 0.244587909 MIA PBI 0.824144687 MIA MIA 0.484907626 NYC EWR 0.731075565 NYC LGA 0.708648915 NYC HPN 0.523991258 LAX LGB 0.651847818 LAX LAX 0.423607479 LAX SNA 0.433837044 LAX ONT 0.723144957 Other MCO 0.657586674 Other SJC 0.084138321 Other OAK 0.698794154 Other BOS 0.85765002 Other BNA 0.018953126 Other WAS 0.234897245 https://i.stack.imgur.com/G1E2k.jpg I'm trying to reproduce

How to add label to geom_segment at the start of the segment?

浪尽此生 提交于 2021-02-18 06:25:31
问题 I'm sure this is simple but I can't figure it out. I have the following chart: library(data.table) library(magrittr) library(ggplot2) cambodia <- data.table(Period = c("Funan", "Chenla/Zhenla","Khmer Empire","Dark Ages of Cambodia"), StartDate = c(-500,550,802,1431), EndDate = c(550,802,1431,1863), Color = c("lightblue","lightgreen","lightyellow","pink")) %>% extract(order(-StartDate)) %>% extract(, Period := factor(Period,levels = Period)) ggplot() + geom_segment(data=cambodia, aes(x