[This article was first published on Tag: r – Appsilon | Enterprise R Shiny Dashboards, and kindly contributed to R-bloggers]. (You can report issue about the content on this page here)


Want to share your content on R-bloggers? click here if you have a blog, or here if you don’t.

Posit Connect is often the de facto platform to deploy R/Shiny applications, Python applications, and Quarto-Shiny documents. And when something goes wrong, we immediately go and visit the logs. But often the logs are walls of text that we have to scour through and when you have been coding and debugging for hours, it is often that you miss the crucial line that could have pointed you right at the error.

We faced a similar problem earlier this year in our collaboration at Elkem, one of the world’s leading silicon manufacturers, where we have multiple apps per project deployed for multiple locations with varying levels of access. In about a week, thanks to an already documented idea, we were able to set up a rudimentary version of LogAnalyzer.

As we became heavy users of the app, we decided its value was too much to keep it to ourselves. Thanks to the openness of the team at Elkem, we are now able to present an open-source version of the same app.

To read more about our overall collaboration with them, you can visit the case study.

While there are other very capable log-monitoring tools like Grafana, setting them up is somewhat complicated and requires you setting up a whole infrastructure, perhaps, on a cloud provider. Often, there is a huge amount of collaboration and process management involved and not everyone has that kind of time or resources.

LogAnalyzer’s value is in how easy it is to set up and use, and how it leverages the existing Posit Connect infrastructure. The simplicity and ease of use and setup is often all you need. That’s where LogAnalyzer comes in. It’s ready to use out of the box,  is set up with a simple deployment that can be made by anyone who has access to the Posit Connect server.

🤔 How LogAnalyzer Works

The LogAnalyzer app has three panes, as you can see in the GIF above. The first pane is simply the list of Deployments available on the Posit Connect server it is deployed on. The second pane lets you pickup a job (deployment or run) based on the Job Id.

There is also the timestamp placed conveniently for you to check the deployment you want to explore.  And then, you get semantically coloured logs for the Deployment and the Job in question.

🔴 Reds signify all stderr statements (and some nifty keywords such as ‘halt’ or ‘terminate’).

🟡 Yellows are the stdout statements.

🟢 Greens are, well, just simple prints and other harmless lines. A simple glance can now tell you what went wrong.

What’s more? If you prefer to look at the text version, there is a download button available for you to download it. And since the app is powered by reactable under the hood, every part of it is searchable, making it even easier for you to find that pesky bug.

🔧 How to Use LogAnalyzer

Here comes the beautiful part. You don’t have to do anything. Deploying your own copy of LogAnalyzer is as simple as 1, 2, 3.

Under the hood, LogAnalyzer uses Appsilon’s {rhino}, which enables an industry-best practices approach to R/Shiny app development so you can be rest assured it’s built with an opinionated approach in mind. Also, the views leverage the popular {reactable} package so everything is searchable. The three panes are, in essence, three heavily customised reactable tables. And the app uses Posit Connect’s official API so all your data passes through secure channels, seamlessly.

Explore the capabilities of the Rhino package and start building your first app today by following our step-by-step tutorial.

1. Clone the App

You can check out the GitHub repository. If you prefer to use the terminal, it’s as simple as:

git clone git@github.com:Appsilon/LogAnalyzer.git

2. Deploy the App

Before you do this step, we recommend restore the {renv} environment using:

renv::restore()

Alternatively, if you want to test the app locally first, you may have to add some necessary environment variables to your .Renviron file on your own (you can use the usethis::edit_r_environ() from the {usethis} package to do this as well).

Here, you can set the CONNECT_SERVER and CONNECT_API_KEY environment variables and don’t forget to restart your session.

  • The CONNECT_SERVER is the address to your Posit Connect instance. If you access your apps using connect.yourorganisation.com/app1, the CONNECT_SERVER value is connect.yourorganisation.com.
  • The CONNECT_API_KEY can be generated from the Posit Connect dashboard and grants the user programmatic access to all deployments. The documentation for the Posit Connect API can be found here.

Note that these environment variables are available to default to any deployed app on Posit Connect, and you only need to set these up locally. To learn more about them and to generate an API key, you can check the official Posit Connect documentation.

👉 Tip: You can also change the logo in app/static and modify the mod_header.R to make it truly your own.

Now, you can simply deploy the application to Posit Connect either with the {rsconnect} package or with the RStudio GUI

3. Set CONNECT_API_KEY (or not)

There are two ways to go about this: either let Posit Connect set the CONNECT_API_KEY for you automatically or set the environment variable in the Vars section of the Posit Connect GUI for the application yourself.

What’s the difference between these two approaches? It boils down to who is using LogAnalyzer and the intended usage.

  • If you are deploying LogAnalyzer for personal use and want to analyse logs only for your own apps—that you deploy yourself—then use the first approach and let it all work on its own. You don’t need to set up an environment variable at all.
  • If you want LogAnalyzer to be accessed team-wide with access to all logs for all deployments to all users, you could manually set up a key for a user with Admin rights or who belongs to the group with access to all apps. This way, the LogAnalyzer instance would be able to fetch logs regardless of who deployed the app.

Either way, the CONNECT_SERVER will be set for you and defaults to the server the application is deployed on.

And voila 🪄! That really is it. You have your own instance of LogAnalyzer deployed and ready to use. No more sifting through long chunks of text!

📎 An Ending Note

We invite you to find issues with the application as well as think of potential improvements. If and when you see a way you can improve this application, feel free to raise an issue or a pull request. We look forward to your contributions!

Frequently Asked Questions

Q: What types of applications does LogAnalyzer support?

A: LogAnalyzer currently supports log monitoring for R/Shiny applications, Python applications, and Quarto-Shiny documents deployed on Posit Connect.

Q: Can I use LogAnalyzer for applications not deployed on Posit Connect?

A: No, LogAnalyzer is designed to work with the Posit Connect infrastructure and leverages the Posit Connect API to fetch log data.

Q: How does LogAnalyzer handle large log files?

A: LogAnalyzer uses the {reactable} package under the hood, which allows for efficient rendering and searching of large datasets, including log files.

Q: Can I customize the color scheme for log entries?

A: Yes, the color scheme for log entries (red, yellow, green) can be customized by modifying the appropriate CSS styles in the app’s code.

Q: Is LogAnalyzer open-source?

A: Yes, LogAnalyzer is an open-source project, and you can find the repository on GitHub. 

Got questions or feedback? Join our community and start a conversation!

The post appeared first on appsilon.com/blog/.

To leave a comment for the author, please follow the link and comment on their blog: Tag: r – Appsilon | Enterprise R Shiny Dashboards.

R-bloggers.com offers daily e-mail updates about R news and tutorials about learning R and many other topics. Click here if you’re looking to post or find an R/data-science job.


Want to share your content on R-bloggers? click here if you have a blog, or here if you don’t.

Continue reading: LogAnalyzer: An Easy-to-Use Log Monitoring Tool for R/Shiny Applications

Analysis of LogAnalyzer: The Easy-to-Use Log Monitoring Tool for R/Shiny Applications

In a world where Posit Connect stands as the usual platform for deploying R/Shiny applications, Python applications, and Quarto-Shiny documents, the efficient processing of log data is critical. However, constantly parsing walls of log text can take a toll on developers. This led to the development of LogAnalyzer, a tool resulting from a collaboration at Elkem. Its open-source version has proven to be an invaluable tool for numerous application deployments. There are some key points to consider about this powerful tool, its long-term implications, potential improvements, and how developers could leverage it in the future.

Long-term implications and potential future developments

A significant advantage of LogAnalyzer is its simplicity. It can be set up and deployed without an extensive infrastructure or a time-consuming collaborative process. By harnessing the existing Posit Connect infrastructure, LogAnalyzer offers a straightforward and secure approach to log data analysis. This simplicity will likely encourage even more developers to adopt LogAnalyzer in the long term.

LogAnalyzer has been designed in a way that enhances user experience. Users can easily navigate through and explore the error messages, which are colour-coded to differentiate among stderr statements, stdout statements, and harmless print lines. Greens represent benign lines, yellows indicate stdout statements, and reds denote stderr statements and specific keywords.

One future advantage lies in LogAnalyzer’s extensibility. Developers could tweak the app to meet their specified needs because it’s open-source. They can even modify the CSS styles to change the colour scheme of the logs. Also, the potential future inclusion of such customization features in the app could dramatically enhance the user experience.

Actionable Advice

To incorporate LogAnalyzer into the workflow, users can follow a three-step process- Clone the App, Deploy the App, and Set Connect API Key. Clone the app from GitHub, deploy it on Posit Connect via the rsconnect package or RStudio GUI, and set the API key for authorization. Although Posit Connect automatically sets the key, users have the option to manually set it. This flexibility enables developers to use LogAnalyzer both at a personal level and team-wide, offering a versatile tool for log monitoring.

The use of Appsilon’s rhino for best practices and the popular reactable package enables powerful search features and the possibility to handle large log files. This makes LogAnalyzer an efficient and convenient tool for developers. It’s recommended to explore the various capabilities of the Rhino package and start building apps using it.

Developers should also consider actively contributing to the open source project. It’s not just about using the tool, but also finding issues, suggesting improvements, and even making pull requests, which will not only enhance their development skills but also support the broader developer community.

In conclusion, exploring the features of LogAnalyzer and integrating it into the development workflow could prove invaluable, especially in the long run, considering the time and resources saved from the process. Further, sharing issues and improvements with the community can help optimize the tool for better handling of log data across various deployments.

Read the original article